Remove Duplicates Preserving Order
Problem Given an array, return its elements with duplicates removed, keeping each value's first-occurrence order. Sorting is not allowed, since it would destroy the original order.
Input / Output
- Input: array arr of n elements.
- Output: the distinct elements in the order they first appear.
Constraints
- 1 <= n <= 10^5.
- Preserve original relative order; do not sort.
Example
- [3,1,3,4,1,5] -> [3,1,4,5]
- [7,7,7] -> [7]
added …