Skip to content

Commit 57a5d0f

Browse files
committed
clarified explanation
1 parent 9c36cab commit 57a5d0f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Sprint-1/JavaScript/findCommonItems/findCommonItems.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Finds common items between two arrays.
33
*
4-
* Time Complexity: O(n*m) where n and m are length of each array
4+
* Time Complexity: O(n*m) or O(n^2) where n and m are length of each array
55
* Space Complexity: O(n) where n is a length of arrays
66
* Optimal Time Complexity: O(n)
77
*
@@ -14,6 +14,7 @@ export const findCommonItems = (firstArray, secondArray) => {
1414
// program flow:
1515
// firstArray.filter go through the each item in first array (loop)
1616
// secondArray.includes check if that item is in the second array (nested loop)
17+
// then, from new filtered array we create a Set which is not a nested array, but still O(n) operation
1718
// nested loop result in O(n^2) time complexity
1819

1920
// to reduce time complexity to sublinear on the number of elements in the arrays we can use Set and it's .intersection() method

Sprint-1/Python/remove_duplicates/remove_duplicates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def remove_duplicates(values: Sequence[ItemType]) -> List[ItemType]:
2323
# unique_items.append(value)
2424

2525
# return unique_items
26-
# nested array O(n^2) complexity
26+
# nested array - O(n^2) complexity
2727

28-
# here we iterate through the array to make a dict which is O(n) and than convert it to the list which is also 0(n)
28+
# here we iterate through the array to make a dict which is O(n) and than convert it to the list which is also O(n)
2929
return list(dict.fromkeys(values))

0 commit comments

Comments
 (0)