write a program to find out suffix of two strings are same
Interview Answers
Anonymous
14 Feb 2018
Always remember suffix means not the last letter but all those matching letters counting backwards from the last letter.
Anonymous
31 Aug 2018
Here is my solution for the same -
public static void commonSuffix(String s1, String s2) {
String res = "";
for(int i=s1.length()-1,j=s2.length()-1;i>=0 && j>=0;i--,j--) {
if(s1.charAt(i)==s2.charAt(j)) {
res = s1.charAt(i)+res;
}else {
break;
}
}
System.out.print(res);
}