diff --git a/medium/find_the_prefix_common_array_of_two_arrays.py b/medium/find_the_prefix_common_array_of_two_arrays.py new file mode 100644 index 0000000..d840b2f --- /dev/null +++ b/medium/find_the_prefix_common_array_of_two_arrays.py @@ -0,0 +1,18 @@ +# https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays + +from typing import List + +class Solution: + def findThePrefixCommonArray(self, A: List[int], B: List[int]) -> List[int]: + result = [] + count = {} + curr = 0 + for i in range(len(A)): + count[A[i]] = count.get(A[i], 0) + 1 + if count[A[i]] > 1: + curr += 1 + count[B[i]] = count.get(B[i], 0) + 1 + if count[B[i]] > 1: + curr += 1 + result.append(curr) + return result