Skip to content

Commit 552f663

Browse files
committed
Jan 14
1 parent a372b2e commit 552f663

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def findThePrefixCommonArray(self, A: List[int], B: List[int]) -> List[int]:
6+
C, count, seen = [], 0, set()
7+
for a, b in zip(A, B):
8+
if a in seen:
9+
count += 1
10+
else:
11+
seen.add(a)
12+
if b in seen:
13+
count += 1
14+
else:
15+
seen.add(b)
16+
C.append(count)
17+
return C
18+
19+
20+
def main():
21+
A = [1, 3, 2, 4]
22+
B = [3, 1, 2, 4]
23+
assert Solution().findThePrefixCommonArray(A, B) == [0, 2, 3, 4]
24+
25+
A = [2, 3, 1]
26+
B = [3, 1, 2]
27+
assert Solution().findThePrefixCommonArray(A, B) == [0, 1, 3]
28+
29+
30+
if __name__ == '__main__':
31+
main()

2025-01-January-LeetCoding-Challenge/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
| January 11 | [1400. Construct K Palindrome Strings](https://leetcode.com/problems/construct-k-palindrome-strings/) | Medium | Solved |
1717
| January 12 | [2116. Check if a Parentheses String Can Be Valid](https://leetcode.com/problems/check-if-a-parentheses-string-can-be-valid/) | Medium | Unsolved |
1818
| January 13 | [3223. Minimum Length of String After Operations](https://leetcode.com/problems/minimum-length-of-string-after-operations/) | Medium | Solved |
19-
| January 14 | []() | | |
19+
| January 14 | [2657. Find the Prefix Common Array of Two Arrays](https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays/) | Medium | Solved |
2020
| January 15 | []() | | |
2121
| January 16 | []() | | |
2222
| January 17 | []() | | |
@@ -40,5 +40,5 @@
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
4242
| Easy | 4 | 4 | 0 |
43-
| Medium | 9 | 8 | 1 |
43+
| Medium | 10 | 9 | 1 |
4444
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)