Remove duplicates with a generic helper
Return unique primitive values in first-occurrence order; numeric 1 and string "1" are distinct. Implement a generic helper for strings and numbers. Inputs are valid JSON and must not be modified unless the algorithm uses a local copy. This exercise probes typed data modeling, boundary handling, and algorithm selection.
Input
One JSON value: (string | number)[]. See the sample for its exact shape.
Output
One compact JSON value of type (string | number)[]. Strings include JSON quotes; arrays preserve the specified order.
Constraints
Array/string lengths are 0 to 10000 unless stated otherwise. Numbers are integers in [-1000000,1000000]; all computed results fit the safe integer range.
Example
Input
[1,"1",1,"a","a"]
Output
[1,"1","a"]
Example 2 input
[2,1,2,3]
Output
[2,1,3]
Checks a boundary or contrasting case beyond the public examples.
Public test cases (2)
Input
[1,"1",1,"a","a"]
Expected output
[1,"1","a"]
Input
[]
Expected output
[]
Hints (2)
- Start with the required output order and the empty-input behavior.
- Prefix dictionary keys with their primitive type
Target complexity: time O(n) · space O(n)
