Here is the interview question prompt, presented for reference.
Given an array, return another array with just the ordered unique elements from the given array. In other words, you're removing any duplicates.
Note: Order needs to be preserved, so no sorting should be done. And the order should be maintained with the first occurrence of the element in the given array.
function uniques(arr) {
// fill in
}
let arr = [3, 5, 6, 9, 9, 4, 3, 12]
uniques(arr);
// Correct: [3, 5, 6, 9, 4, 12]
// But this is incorrect: [5, 6, 9, 4, 3, 12]
arr = [13, 5, 3, 5, 8, 13, 14, 5, 9]
uniques(arr);
// Correct: [13, 5, 3, 8, 14, 9]
// Incorrect: [3, 5, 8, 13, 14, 9]
100000
-1000000000
and 1000000000
O(n)
O(n)
You can see the full challenge with visuals at this link.
Challenges • Asked almost 7 years ago by Jake from AlgoDaily
This is the main discussion thread generated for Remove Duplicates From Array.