Meta VO Interview Problem: Print Missing Numbers | Array Traversal and Range Output

19 Views
No Comments

Q2: Print missing numbers

Input: [2, 4, 7, 13, 20]

Output: "0,1,3,5,6,8-12,14-19,21-99"

Given a sorted list of numbers, print all missing numbers in the range from 0 to 99. Consecutive missing values should be compressed into ranges.

The key idea is to scan the sorted array and print every number missing from the range <code>0</code> to <code>99</code>, compressing consecutive gaps into intervals. A clean solution checks the missing prefix before the first value, the gaps between adjacent values, and the suffix after the last value up to <code>99</code>. This is a classic OA-style array traversal and formatting problem with careful boundary handling.

END
 0