Help me figure out what's wrong with the Python code below. It's supposed to count the number of characters that overlap between the beginning of one string and the end of another. overlap('CTAAGT', 'TTCA') should return 1, but instead it returns 2.

def overlap(string1, string2):
    if len(string2) < len(string1):
        temp = string1
        string1 = string2
        string2 = temp

    print("string1: " + string1)
    print("string2: " + string2)
    
    for i in range(0, len(string1) + 1):
        print(f'{string1[i:]} == {string2[:(len(string1) - i)]}')
        if (string1[i:] == string2[:(len(string1) - i)]):
            break

    for j in range(0, len(string1) + 1):
        print(f'{string2[j:]} == {string1[:(len(string2) - j)]}')
        if (string2[j:] == string1[:(len(string2) - j)]):
            break

    return max(len(string1) - i, len(string2) - j)
user