Palo Alto Interview Question: Missing Ranges from a Sorted Integer List

14 Views
No Comments

Problem Description

You are given a sorted list of distinct integers ranging from 0 to 99.

For example:

[0, 1, 2, 50, 52, 75]

Your task is to produce a string that describes the numbers missing from the list.

In this example, the missing numbers are:

3–49, 51, 53–74, 76–99

Examples

Input:  []
Output: "0-99"
Input:  [0]
Output: "1-99"
Input:  [1, 99]
Output: "0, 2-98"
Input:  [3, 5]
Output: "0-2, 4, 6-99"

This problem asks you to scan a sorted list of integers and generate a compact string representing the missing ranges within a fixed boundary.
The solution requires careful handling of edge ranges, single missing values, and continuous intervals, all in a single linear pass.

END
 0