0

I am trying to generate the longest repeating subsequence but the output appears to be incorrect for a few cases.

Below is the code block I am using

def LRSLength(X, m, n):

    # return if the end of either string is reached
    if m == 0 or n == 0:
        return 0

    # if characters at index `m` and `n` matches and the index are different
    if X[m - 1] == X[n - 1] and m!=n:
        return LRSLength1(X, m - 1, n - 1) + 1

    # otherwise, if characters at index `m` and `n` don't match
    return max(LRSLength(X, m, n - 1), LRSLength(X, m - 1, n))

Though, when I call:

LRSLength([1,1],2,2), output=1.

LRSLength1([1,1,1,1],4,4), output=3

LRSLength1([1,1,1,1,2,2,1,1,1,1,1],11,11), output=8

Can anyone help me where I am going wrong?

Mehul Gupta
  • 1,829
  • 3
  • 17
  • 33

0 Answers0