S Write and test a function that finds and returns through a
S. Write and test a function that finds and returns through an output parameter the longest common suffix of two words (e.g., the longest common suffix of procrastination\" and \"destination is \"stination\", of \"globally\" and \"internally\" is \"all and of \"gloves\" and \"dove\" is the empty string).
Solution
i think the logic i written below is perfect at max.
x=\'procarstination\'
y=\'destination\'
list1=[]
list2=[]
for i in x:
list1.append(i)
for i in y:
list2.append(i)
list1.reverse()
list2.reverse()
len1=len(list1)
len2=len(list2)
final=[]
count=1
if len1>len2:
for i in range(len(list2)-1):
if list1[i]==list2[i] and list1[i+1]==list2[i+1]:
count+=1
else:
for i in range(len(list1)-1):
if list1[i]==list2[i] and list1[i+1]==list2[i+1]:
count+=1
for i in range(count):
final.append(list1[i])
print(count)
final.reverse()
str1=\'\'
for i in final:
str1+=i
print(str1)
