Section 1Understand Problem
Section 01
Understand the problem
Restate the problem precisely. Interviewers reward candidates who pause, define the contract, and name the guarantees before coding.
Problem statement
You are given a sorted unique integer array `nums`. A *range* `[a, b]` is the set of all integers from `a` to `b` (inclusive). Return the *smallest sorted* list of ranges that cover all the numbers in the array exactly. That is, each element of `nums` is covered by exactly one of the ranges, and there is no integer `x` such that `x` is in one of the ranges but not in `nums`. Each range `[a, b]` in the list should be output as `"a->b"` if `a ≠ b`, or `"a"` if `a == b`.
Example
nums = [0,1,2,4,5,7] → ["0->2","4->5","7"]
Constraints
0 ≤ nums.length ≤ 20 · −2³¹ ≤ nums[i] ≤ 2³¹ − 1 · All values are unique and sorted
Audio recording unsupported on this browser.
WPM—Fillers0Pace—Thinking0%
Explain the problem in your own words
0 words0 chars
AI Review
Write your thinking above first.
Once you've drafted a response, click Submit for AI review and a senior engineer will critique your reasoning.
Ready to submit Section 1?
The reviewer will check whether you stated inputs, output, guarantees, and any assumption you flagged.
Write at least a couple of sentences explaining the problem before submitting.