
    Given a sequence of transaction location codes from a customer's credit card usage history, determine the length of the longest pattern of locations that forms the same sequence when read forwards and backwards, as this could indicate coordinated fraud through deliberate transaction paths. For example, in a sequence of locations A-B-C-B-A, the entire sequence of 5 locations forms a suspicious pattern that reads the same in both directions.
    

    
def lps(str):
    """
    Given a sequence of transaction location codes from a customer's credit card usage history, determine the length of the longest pattern of locations that forms the same sequence when read forwards and backwards, as this could indicate coordinated fraud through deliberate transaction paths. For example, in a sequence of locations A-B-C-B-A, the entire sequence of 5 locations forms a suspicious pattern that reads the same in both directions.
    

    """
def lps(str):
    """
    Given a sequence of transaction location codes from a customer's credit card usage history, determine the length of the longest pattern of locations that forms the same sequence when read forwards and backwards, as this could indicate coordinated fraud through deliberate transaction paths. For example, in a sequence of locations A-B-C-B-A, the entire sequence of 5 locations forms a suspicious pattern that reads the same in both directions.
    

    """
    n = len(str)
    L = [[0 for x in range(n)] for x in range(n)]
    for i in range(n):
        L[i][i] = 1
    for cl in range(2, n + 1):
        for i in range(n - cl + 1):
            j = i + cl - 1
            if str[i] == str[j] and cl == 2:
                L[i][j] = 2
            elif str[i] == str[j]:
                L[i][j] = L[i + 1][j - 1] + 2
            else:
                L[i][j] = max(L[i][j - 1], L[i + 1][j])
    return L[0][n - 1]