All problems
0269EasyArray

Retained Revision Report

Tracked in this browser only
Write code

Trains the technique from

LeetCode 228Summary Ranges

This 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 stretch running from a through b where b is larger than a is written "a..b"
  • a stretch holding only the number 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.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def retained_revision_report(revisions: list[int]) -> list[str]:
Java
public List<String> retainedRevisionReport(int[] revisions)
September 7
Apply