In two strings:
\"Mary Had a Little Lamb\"
\"Mary Had a Big Lamb\"
should return
\"Mary Had a \"
public class Test{
public static void main(String[] args){
String s1 = "Mary Had a Little Lamb";
String s2 = "Mary Had a Big Lamb";
int minStrLen = s1.length();
if ( minStrLen > s2.length()){
minStrLen = s2.length();
}
StringBuilder output = new StringBuilder();
for(int i=0; i
This may not be the optimum solution, but this is easy to understand and program.
I borrowed this idea from the list merging technique of merge-sort algorithm. If you read little about list merging technique you will better understand the logic of my algorithm.