56. Remove Duplicates from Sorted Array
EasyTwo Pointers
The array is sorted. Print the number of distinct values on the first line and the distinct values in order on the second line.
Input format
Line 1: n Line 2: n sorted integers
Output format
Line 1: count Line 2: distinct values
Example 1
Input
6 1 1 2 3 3 3
Output
3 1 2 3
Example 2
Input
3 5 5 5
Output
1 5
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…