2657. Find the Prefix Common Array of Two Arrays

class Solution:
    def findThePrefixCommonArray(self, A: List[int], B: List[int]) -> List[int]:
        matchCount = 0
        n = len(A)
        c = [0] * n
        aSet = set()
        bSet = set()

        for i in range(n):
            if A[i] in bSet:
                matchCount += 1

            if B[i] in aSet:
                matchCount += 1

            if A[i] == B[i]:
                matchCount += 1

            c[i] = matchCount

            aSet.add(A[i])
            bSet.add(B[i])


        return c