Tap here to switch tabs
Problem
Submissions

Problem: Summary Ranges

med
30 min
Try to solve the Summary Ranges problem.

Statement

Given a sorted integer array nums with all distinct values, return the smallest list of ranges that exactly covers every number in nums.

A range represents a maximal consecutive sequence of integers in nums. For each such sequence:
If the sequence contains exactly one number x, output the string "x".
Otherwise, if the sequence starts at a and ends at b, output the string "a->b".

Return the ranges in the same order as they appear in nums.

Constraints:

  • 0≤0 \leq nums.length ≤20\leq 20

  • −231≤-2^{31} \leq nums[i] ≤231−1\leq 2^{31} - 1

  • All values in nums are unique.

  • nums is sorted in ascending order.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Summary Ranges

med
30 min
Try to solve the Summary Ranges problem.

Statement

Given a sorted integer array nums with all distinct values, return the smallest list of ranges that exactly covers every number in nums.

A range represents a maximal consecutive sequence of integers in nums. For each such sequence:
If the sequence contains exactly one number x, output the string "x".
Otherwise, if the sequence starts at a and ends at b, output the string "a->b".

Return the ranges in the same order as they appear in nums.

Constraints:

  • 0≤0 \leq nums.length ≤20\leq 20

  • −231≤-2^{31} \leq nums[i] ≤231−1\leq 2^{31} - 1

  • All values in nums are unique.

  • nums is sorted in ascending order.