EasyPythonJavaScriptTypeScript
Unique Array
ArraysFunctions
Implement solve(arr) that returns a new array containing only the
first occurrence of each element, preserving the original order.
Examples
solve([1,2,1,3,2])→[1,2,3]solve([])→[]solve(['a','b','a'])→['a','b']
Constraints
- Elements are compared by value (primitives only).
- Maintain insertion order.
Sample tests
Test #1Empty array
Input: [[]]
Output: []
Test #2Numbers with duplicates
Input: [[1,2,1,3,2]]
Output: [1,2,3]
Test #3All identical
Input: [[1,1,1,1]]
Output: [1]
Test #4Strings
Input: [["a","b","a","c","b"]]
Output: ["a","b","c"]
Test #5Multiple duplicates scattered throughout
Input: [[3,1,4,1,5,9,2,6,5,3]]
Output: [3,1,4,5,9,2,6]