public static int longestCommonSubsequence(String A, String B) {
        // write your code here
        int m=A.length(), n=B.length();
        int[][]t=new int[m+1][n+1];
        for (int i=1;i<=m;++i)
            for (int j=1;j<=n;++j)
                if (A.charAt(i-1)==B.charAt(j-1))
                    t[i][j]=t[i-1][j-1]+1;
                else 
                    t[i][j]=Math.max(t[i-1][j],t[i][j-1]);
        return t[m][n];
    }