428. Summary Ranges
EasyArray
The array is sorted with distinct values. Summarise it as ranges: "a->b" for runs of consecutive numbers and "a" for single numbers, separated by spaces.
Input format
Line 1: n Line 2: n sorted distinct integers
Output format
The ranges.
Example 1
Input
6 0 1 2 4 5 7
Output
0->2 4->5 7
Example 2
Input
7 0 2 3 4 6 8 9
Output
0 2->4 6 8->9
Constraints
1 ≤ n ≤ 10⁴
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…