You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-1/Python/find_common_items/find_common_items.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -9,8 +9,8 @@ def find_common_items(
9
9
"""
10
10
Find common items between two arrays.
11
11
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.
14
14
Optimal time complexity: The time complexity is O(n + m) and the space complexity is O(n + m).
0 commit comments