FastPrepSummary Ranges
Problems/Summary Ranges

Summary Ranges

Indeed logoIndeed● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: A phone interview report names two questions, Summary Ranges and Two Sum. This is the Summary Ranges question.

The report gives no input format, output format or limits. Here, you get a strictly increasing array of 32-bit integers, which may be empty, and return the runs of consecutive numbers in order. A run is written as "a->b", and a single number is written alone. The array length limit is a practice choice.

The judged task matches the report at about 80%.

You are given an integer array nums sorted in strictly increasing order. Split it into runs of consecutive integers, where each number in a run is exactly one more than the number before it. Make every run as long as it can be, so there are as few runs as possible.

Return one string for each run, in order:

  • "a->b" for a run that starts at a and ends at a different number b.
  • "a" for a run made of the single number a.

If nums is empty, return an empty list.

Function

summaryRanges(nums: int[]) → List<String>

Examples

Example 1

nums = [-3,-2,-1,4,6,7]return = ["-3->-1","4","6->7"]

-3, -2 and -1 are consecutive, so they form "-3->-1". 4 stands alone, because 3 and 5 are missing. 6 and 7 form "6->7".

Example 2

nums = [0,2,4,5]return = ["0","2","4->5"]

0 and 2 are each alone, since 1 and 3 are missing. 4 and 5 are consecutive and form "4->5".

Example 3

nums = []return = []

There are no numbers, so there are no ranges.

Constraints

  • 0 <= nums.length <= 1000
  • -2^31 <= nums[i] <= 2^31 - 1
  • nums is sorted in strictly increasing order.

More Indeed problems

  • Insert into an Unrolled Linked ListPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Course Completion OrderPHONE SCREEN · Seen May 2025
  • Recipes You Can PreparePHONE SCREEN · Seen May 2025
All Indeed interview questionsSee Indeed hiring insights
Saved
class Solution {
    public List<String> summaryRanges(int[] nums) {
        // Write your code here.
    }
}
Checking account…