Problems > Compact a Sorted Array

Compact a Sorted Array

Difficulty: 900 3500 ms 128 MB

two-pointers

The array is sorted. Print it with consecutive duplicates removed.

Input: the first line has N; the second line has N sorted integers.

Output: the distinct values in order.

Constraints:

  • 1 ≤ N ≤ 105
  • −109 ≤ ai ≤ 109

Sample Tests

Input 1
6
1 1 2 3 3 3
Output 1
1 2 3
Input 2
1
5
Output 2
5

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.