Summary Ranges
Real-world version: Retained Revision ReportThe statement here is our own: the same inputs, outputs and technique.
A build server stamps every artifact it publishes with a signed 32-bit revision number, and a background job prunes old ones, so what is left on disk has holes in it.
revisions holds the revision numbers still on disk, strictly increasing with no repeats. Gather them into stretches of consecutive numbers and describe each stretch with one string:
- a stretch running from
athroughbwherebis larger thanais written"a..b" - a stretch holding only the number
ais written"a"
Return the descriptions in increasing revision order. Each retained revision must belong to exactly one stretch, and no stretch may stop while the very next number is also on disk, so the report is as short as it can be.
Examples
Example 1
- Input
- revisions = [-9, -8, -7, -3, 0, 1, 4]
- Output
- ["-9..-7", "-3", "0..1", "4"]
-9, -8 and -7 follow one another, so one description covers them. -3 sits alone because neither -4 nor -2 is on disk. 0 and 1 pair up, and 4 sits alone.
Example 2
- Input
- revisions = []
- Output
- []
Nothing is on disk, so the report is empty.
Example 3
- Input
- revisions = [2147483645, 2147483646, 2147483647]
- Output
- ["2147483645..2147483647"]
The three largest revision numbers follow one another and collapse into a single description.
Constraints
- 0 <= revisions.length <= 20
- -2^31 <= revisions[i] <= 2^31 - 1
- All the values of revisions are unique.
- revisions is sorted in ascending order.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def retained_revision_report(revisions: list[int]) -> list[str]:public List<String> retainedRevisionReport(int[] revisions)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 7 test cases: 7 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's