public static String getLCSubseq(String str1, String str2) {
        int substringLength1 = str1.length();
        int substringLength2 = str2.length();

        int[][] opt = new int[substringLength1+1][substringLength2+1];
        for (int i = substringLength1-1; i >= 0; i--) {
            for (int j = substringLength2-1; j >= 0; j--) {
                if (str1.charAt(i) == str2.charAt(j))
                    opt[i][j] = opt[i + 1][j + 1] + 1;
                else
                    opt[i][j] = Math.max(opt[i + 1][j], opt[i][j + 1]);
            }
        }

        int i = 0, j = 0;
        String result = "";
        while (i < substringLength1 && j < substringLength2) {
            if (str1.charAt(i) == str2.charAt(j)) {
                result += str1.charAt(i);
                i++;
                j++;
            } else if (opt[i + 1][j] >= opt[i][j + 1]) {
            	i++;
            } else {
                j++;
            }
        }
        return result;
	}