Skip to content

Commit 3300b91

Browse files
authored
Updating comment.
The complexity of the original code was 0( n x m) because for every item in the first_sequence was compared against every item in second_sequence. With the new implementation the time complexity is 0(n + m), because one iteration is made to build second_set; then another iteration through first_sequence.
1 parent 3eadae1 commit 3300b91

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

Sprint-1/Python/find_common_items/find_common_items.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ def find_common_items(
88
) -> List[ItemType]:
99
"""
1010
Find common items between two arrays.
11+
12+
The complexity of the original code was 0( n x m) because for every item in the first_sequence was compared against every item in second_sequence.
13+
With the new implementation the time complexity is 0(n + m), because one iteration is made to build second_set; then another iteration through first_sequence.
1114
1215
Time Complexity: The time complexity is O(n + m)
1316
Space Complexity: The space complexity is O(n + m)
1417
Optimal time complexity: The time complexity is O(n + m)
18+
1519
"""
1620
second_set = set(second_sequence)
1721
seen = set()

0 commit comments

Comments
 (0)