Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Summary Ranges

XPChallenge Points: 10
levelLevel: Easy

You are given a sorted list of unique integers called numbers.
Your task is to generate the smallest set of continuous ranges that exactly cover all integers in the list.
Each range [a, b] should be represented as:
• "a->b" if a and b are different
• "a" if a and b are the same
The result should be returned as a list of strings, sorted in ascending order according to the input sequence.

Example 1:

Input: numbers = [1, 2, 3, 5, 6, 9]

Output: ["1->3", "5->6", "9"]

Example 2:

Input: numbers = [0, 2, 3, 4, 7, 8, 10]

Output: ["0", "2->4", "7->8", "10"]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result