Function for finding unique elements while preserving order

JavaScript Medium functions

Task «Function for finding unique elements while preserving order»

Write a function `uniqueOrdered(arr)` that takes an array of numbers or strings and returns a new array containing only unique elements, preserving their original order. Elements are considered unique if they appear in the array for the first time. The order must match the order of the first occurrence of elements in the input array. The solution must be implemented without using third-party libraries.

Input Format

The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of elements. The second line contains n elements separated by spaces. The elements can be numbers or strings (without spaces).

Output Format

Output the unique elements of the array in the order of their first occurrence, separated by spaces.

Examples

Example 1

INPUT
5 a b a c b
OUTPUT
a b c

Example 2

INPUT
Война и мир 1869 1984 1949 Джордж Оруэлл
OUTPUT
Война и мир 1869 1984 1949 Джордж Оруэлл

Example 3

INPUT
1 42
OUTPUT
42

Example 4

INPUT
Мастер и Маргарита 1967 Улисс 1922 Джеймс Джойс
OUTPUT
Мастер и Маргарита 1967 Улисс 1922 Джеймс Джойс
main.js