Not passing the testcases,,,,Problem title: print Longest Common Subseq

import java.util.*;

public class Main {
public static String max_length_string(String x,String y){

return (x.length()>y.length())?x:y;
}
public static String LCS(String a,String b,HashMap<String,String> faf){

String result="";

if(a.length()==0 || b.length()==0){

    return "";
}

if(faf.containsKey(a+"**"+b)){

    return faf.get(a+"**"+b);
}
if(a.charAt(0)==b.charAt(0)){

    result=result+Character.toString(a.charAt(0))+LCS(a.substring(1),b.substring(1),faf);
}
 else{

 result=result+max_length_string(LCS(a.substring(1),b,faf),LCS(a,b.substring(1),faf));

 }
 faf.put(a+"**"+b,result);

 return result;
}
public static void main(String args[]) {
    Scanner st=new Scanner(System.in);

 String s1=st.nextLine();
 String s2=st.nextLine();
 HashMap<String,String> faf=new HashMap<>();
 System.out.println(LCS(s1,s2,faf));

}

}

Hi Divyansh

For the input abbae and gbdea, output should be be whereas your code gives ba.

But ba is also a valid common subseq.
I do understand ba and be are 2 possible subseqs with max length 2.
further in question one constraint was mentioned, i.e given input will never have more than one possible answers.

Hi Divyansh

I just checked at the backend. There was some problem with the test case. You can submit your code now. It should work fine now.

Hi Divyansh

As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.