Trains the technique from
LeetCode 228Summary RangesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
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 through b where b is larger than a is written "a..b"a is 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.
Example 1
-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
Nothing is on disk, so the report is empty.
Example 3
The three largest revision numbers follow one another and collapse into a single description.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def retained_revision_report(revisions: list[int]) -> list[str]:public List<String> retainedRevisionReport(int[] revisions)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.