Skip to content

Commit 14db9b9

Browse files
authored
Refine complexity analysis in find_common_items function
Updated time and space complexity explanations in docstring.
1 parent 7ad8c1f commit 14db9b9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sprint-1/Python/find_common_items/find_common_items.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ def find_common_items(
99
"""
1010
Find common items between two arrays.
1111
12-
Time Complexity: for each element in first_sequence, is compared against every element in second_sequence.
13-
Space Complexity: O(the number of unique common elements)
12+
Time Complexity: The time complexity is O(n + m) because we build a set from the second sequence in O(m) time and iterate through the first sequence in O(n) time.
13+
Space Complexity: The space complexity is O(n + m) because we store up to all elements of the second sequence in a set and up to the common elements in additional storage.
1414
Optimal time complexity: The time complexity is O(n + m) and the space complexity is O(n + m).
1515
"""
1616
second_set = set(second_sequence)

0 commit comments

Comments
 (0)