Microsoft OA Interview Question: Missing Ranges in a Sorted List

18 Views
No Comments

You are given a sorted list of distinct integers from 0 to 99, for instance [0, 1, 2, 50, 52, 75].

Your task is to produce a string that describes the numbers missing from the list; in this case "3,49,51,53-74,76-99".

This problem asks you to scan a sorted list of distinct integers in the range 0 to 99 and return a compact string describing all missing values. The key idea is to compare neighboring numbers, emit single missing numbers directly, and merge longer gaps into ranges such as 53-74. You also need to handle missing numbers before the first element and after the last element. A simple linear pass is enough, making the solution straightforward and efficient.

END
 0