Skip to content

Commit ef4739b

Browse files
committed
fix: optimize membership check using set instead of list
1 parent 177e3af commit ef4739b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sprint-1/Python/find_common_items/find_common_items.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ def find_common_items(
2020
second_set = set(second_sequence)
2121

2222
# Find common items using set lookup: O(n) time
23+
seen_items = set()
2324
common_items = []
2425
for item in first_sequence:
25-
if item in second_set and item not in common_items:
26+
if item in second_set and item not in seen_items:
2627
common_items.append(item)
28+
seen_items.add(item)
2729

2830
return common_items
2931

0 commit comments

Comments
 (0)