#K34897. Remove Consecutive Duplicates
Remove Consecutive Duplicates
Remove Consecutive Duplicates
Given a list of strings, your task is to remove all consecutive duplicate strings and output the resulting list. In other words, whenever there are one or more occurrences of the same string in a row, only the first occurrence should be kept.
Example:
Input: a a b b b c a a Output: a b c a
Note: If the input list is empty, output an empty line.
Formally, if the input list is \( a_1, a_2, \dots, a_n \), you need to produce a list \( b_1, b_2, \dots, b_k \) such that:
[ b_1 = a_1, \quad b_i = a_j \quad \text{for the smallest } j > i \text{ satisfying } a_j \neq a_{j-1}. ]
This problem tests your ability to manipulate lists and handle edge cases.
inputFormat
The input is given from stdin
in the following format:
- The first line contains an integer \( n \) \( (0 \leq n \leq 10^5) \) representing the number of strings.
- The second line contains \( n \) strings separated by spaces.
If \( n = 0 \), the second line may be omitted and you should output an empty line.
outputFormat
Print to stdout
a single line containing the list of strings after removing consecutive duplicates. The strings should be separated by a single space.
8
a a b b b c a a
a b c a