#K73897. Unique Elements
Unique Elements
Unique Elements
You are given an array of integers. Your task is to remove all duplicate elements from the array while preserving the order in which they first appear. In other words, given an array \(A=[a_1, a_2, \dots, a_n]\), output an array \(B\) such that each element from \(A\) appears only once in \(B\) in the order of its first occurrence.
Examples:
- Input: 1 2 2 3 4 4 5, Output: 1 2 3 4 5
- Input: 4 3 2 1 2 3 4, Output: 4 3 2 1
- Input: 7 8 7 9 10, Output: 7 8 9 10
This problem is considered easy and focuses on basic data structures and processing input/output.
inputFormat
The input is read from stdin
and consists of two lines:
- The first line contains a single integer \(n\) (the number of elements in the array).
- The second line contains \(n\) space-separated integers representing the elements of the array.
outputFormat
Print to stdout
the unique elements from the array in the order they first appear, separated by a single space.
5
1 2 3 4 5
1 2 3 4 5