Description
Solutions
Compact the List
🤘 INTERN

Given a sorted list of integers with no duplicates, write an algorithm to compact the list based on a continuous range of numbers. If there are no such ranges available, print the list of strings where each element is a string notation of the number.

Input

The first line of input consists of an integer inputListSize, representing the number of elements in the list (N). The next line consists of N space-separated integers representing the elements of the list.

Output

Print a line-separated list of strings which represents the compacted form of the given list based on a continuous range of numbers.

Note

List is sorted in ascending order.

Example 1:

Input:  inputListSize = 8, inputList = [1, 2, 3, 6, 7, 8, 10, 15]
Output: ["1 to 3", "6 to 8", "10", "15"]
Explanation:

In the given list 1,2,3 form a continuous range and hence are compacted to "1 to 3" and the same for 6,7,8 which are compacted to "6 to 8". But 10 and 15 cannot be compacted so are printed as they are.

Constraints:
    n/a
Thumbnail 0
Testcase

Result
Case 1

input:

output: