Bloomberg | Phone | Find all ranges of consecutive numbers from Array
Anonymous User
2673

Given a sorted array arr[] consisting of N integers without any duplicates, the task is to find the ranges of consecutive numbers from that array.

Examples:
Input: arr[] = {1, 2, 3, 6, 7}
Output: 1->3, 6->7
Explanation:
There are two ranges of consecutive number from that array.
Range 1 = 1 -> 3
Range 2 = 6 -> 7
Input: arr[] = {-1, 0, 1, 2, 5, 6, 8}
Output: -1->2, 5->6, 8

Explanation:
There are three ranges of consecutive number from that array.
Range 1 = -1 -> 2
Range 2 = 5 -> 6
Range 3 = 8

Comments (4)