#K58842. Remove Adjacent Duplicates
Remove Adjacent Duplicates
Remove Adjacent Duplicates
Given a list of integers \(a_1, a_2, \ldots, a_n\), remove all adjacent duplicates so that only the first occurrence in any group of identical consecutive elements is kept.
For example, given the list [1, 2, 2, 3, 4, 4, 4, 5, 1, 1]
, the output should be [1, 2, 3, 4, 5, 1]
. This problem tests your understanding of linear traversal and conditional filtering.
inputFormat
The input is read from standard input and consists of two lines:
- The first line contains a single integer \(n\) \((0 \leq n \leq 10^5)\), representing the number of elements in the list.
- The second line contains \(n\) space-separated integers.
If \(n = 0\), the second line may be empty and the output should be an empty list.
outputFormat
Output the list after removing adjacent duplicates. The list should be printed as space-separated integers on a single line. If the list is empty, print nothing.
## sample10
1 2 2 3 4 4 4 5 1 1
1 2 3 4 5 1