Problem
Return the list with repeated values removed, keeping the first occurrence of each value in its original order.
Implement remove_duplicates(numbers).
Input
numbers: The list of integers.
Output
Return the list without duplicates.
Constraints
0 ≤ length ≤ 100,000
Examples
Input:
numbers = [3, 1, 3, 2, 1]
Expected output:
expected = [3, 1, 2]
Input:
std::vector<long long> numbers = {3, 1, 3, 2, 1};
Expected output:
std::vector<long long> expected = {3, 1, 2};
Input:
long[] numbers = new long[] {3, 1, 3, 2, 1};
Expected output:
long[] expected = new long[] {3, 1, 2};
Explanation
Keep 3, 1, then 2; the later 3 and 1 are dropped: [3, 1, 2].
Input:
numbers = [7, 7, 7]
Expected output:
expected = [7]
Input:
std::vector<long long> numbers = {7, 7, 7};
Expected output:
std::vector<long long> expected = {7};
Input:
long[] numbers = new long[] {7, 7, 7};
Expected output:
long[] expected = new long[] {7};
Explanation
Only the first 7 stays: [7].
How to approach it
Try on your own first, then open one hint at a time.
Hint 1
Keep the first time each value appears and ignore later repeats.
Hint 2
A set or similar lookup helps you decide quickly whether a value was already seen.
Hint 3
Preserve the original order of the first occurrences, not sorted order.
Expected complexity
O(n) time, O(n) extra space
References
This challenge is adapted for CodeUtility. Follow the statement and constraints above.