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
* Remove duplicate values from a sequence, preserving the order of the first occurrence of each value.
3
3
*
4
-
* Time Complexity:
5
-
* Space Complexity:
6
-
* Optimal Time Complexity:
4
+
* Time Complexity: O(n) - where n is the length of the input sequence, as we need to iterate through it once to create the Set.
5
+
* Space Complexity: O(n) - in the worst case, if all elements are unique, the Set will contain all elements of the input sequence. so we need memory to store the unique elements.
6
+
* Optimal Time Complexity: O(n)- using a Set to track seen values allows us to achieve linear time complexity for removing duplicates.
7
7
*
8
8
* @param {Array} inputSequence - Sequence to remove duplicates from
9
9
* @returns {Array} New sequence with duplicates removed
10
10
*/
11
11
exportfunctionremoveDuplicates(inputSequence){
12
+
13
+
return[...newSet(inputSequence)];
14
+
}
15
+
16
+
17
+
// approach 2: map and look up object
18
+
/*export function removeDuplicates(inputSequence) {
0 commit comments