A maintenance tool receives n device serial numbers already sorted in non-decreasing order, so equal serials are adjacent. Collapse each run of equal serials down to a single copy and report how many distinct serials remain.
Line 1: an integer n.
Line 2: n space-separated integers in non-decreasing order.
A single integer: the number of distinct values.
Example 1
Input
6 1 1 2 2 2 5
Expected
3
Explanation
The distinct values are 1, 2 and 5, so the answer is 3.
Example 2
Input
1 7
Expected
1
Explanation
A single serial is already one distinct value: 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →