Find consecutive segments in an sorted array
Problem :
Number list compressing. Given an sorted array. Input: sorted number list [ 1, 2, 3,10, 25, 26, 30, 31, 32, 33]
Output: find consecutive segments print: 1-3, 10, 25-26, 30-33
Logic :
- We need three-pointers to solve this
- First which stays at the start of the sequence,
- Second which stays at the end of the sequence,
- Third which iterates over the array