Testcase 1 is wrong

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
String s1 = scan.next();
String s2 = scan.next();
maxSubseq(s1,s2);
}
public static void maxSubseq(String s1, String s2){
String[][] strg = new String[s1.length()+1][s2.length()+1];
//seed
strg[s1.length()][s2.length()]= “”;
for(int i = s1.length();i>=0;i–){
for(int j= s2.length();j>=0;j–){
if(i==s1.length() || j == s2.length()){
strg[i][j] = “”;
continue; // so that it doesnt go to down statements without fillin last row and column
}
if(s1.charAt(i)==s2.charAt(j)){
strg[i][j] = s1.charAt(i) + strg[i+1][j+1]; // we do this like we call remaining substring
}else{
// deletion vala part
if(strg[i+1][j].length()>strg[i][j+1].length()){
strg[i][j] =strg[i+1][j]; // ros1,s2
}else{
strg[i][j] = strg[i][j+1]; // s1,ros2
}

			}
		}
	}
	System.out.println(strg[0][0]);
}

}

Can you use the concept of finding the length of max subsequence from the given strings using bottom -up approach .Then making an array of the same length , you can further traverse your table which is build in above bottom up approach from the bottom . If you get a matching character then add your character to your array , else update the indexes containing the length of subsequence , accordingly by comparing the value stored at the particular position. This way you will not get confused.