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
{{ message }}
Repository navigation
Commit 902546e
Browse filesBrowse the repository at this point in the historyBrowse files
Fatma Degirmenci
committed
Refactor findCommonItems using a Set for faster lookups
* Time Complexity: We are checking two arrays. If the first array has length n and the second has length m, the time complexity is O(n * m),
5
+
because filter iterates over the first array and includes scans the second array for each element.
6
+
* Space Complexity: A new Set is created to store unique common items, which in the worst case can be the size of the first array --> O(n).
7
+
* Optimal Time Complexity: By converting one array to a Set, we can check membership in O(1) for each element of the other array, reducing the time complexity to O(n + m).
8
8
* @param {Array} firstArray - First array to compare
9
9
* @param {Array} secondArray - Second array to compare
10
10
* @returns {Array} Array containing unique common items
0 commit comments