Today’s challenge
Build the solution
Write a function called compress_ranges(numbers).
Return contract: A list of range strings, such as ["1..3", "7", "10..11"].
Input bounds: 0–500 strictly increasing integers from -1,000,000 through 1,000,000.
Keep the supplied driver below your implementation. It reads one JSON object and prints your return value as JSON. The driver may also probe the behaviour described above; those probe fields are part of the test input.
- Input numbers are already strictly increasing. Group each maximal consecutive run.
- Represent a one-number run as that number in a string. Represent a longer run as start..end, including a run of length two.
- Keep the runs in their original order and return an empty list for empty input.
The Twist: Negative values must stay unambiguous: the consecutive run -3, -2, -1 becomes "-3..-1".
Sample
Input
{"numbers":[1,2,3,7,10,11]}Expected output
["1..3","7","10..11"]