private static int longestCommonSubsequence(int i, int j, char[] seq1, char[] seq2) {
        char x = seq1[i];
        char y = seq2[j];
        int result = 0;
        Set<String> set = sequenceMatrix[i][j];
        if (set == null)
            set = new HashSet<String>();
        if (x == y) {
            if (i > 0 && j > 0)
                set = new HashSet<String>(sequenceMatrix[i - 1][j - 1]);
            distribute(x, set);

            result = (lengthMatrix[i][j]) + 1;
        } else {
            int a = lengthMatrix[i][j + 1];
            int b = lengthMatrix[i + 1][j];

            if (a > b) {
                set = new HashSet<String>(sequenceMatrix[i - 1][j]);

                result = a;
            } else if (b > a) {
                set = new HashSet<String>(sequenceMatrix[i][j - 1]);

                result = b;
            } else if (a == b) {
                if (i > 0 && j > 0) {
                    Set<String> list1 = sequenceMatrix[i - 1][j];
                    Set<String> list2 = sequenceMatrix[i][j - 1];

                    set.addAll(list1);
                    set.addAll(list2);
                }

                result = a; // a==b
            }
        }
        sequenceMatrix[i][j] = set;
        return result;
    }