Report Missing Ranges in a Sorted Post ID Sequence
Last updated: November 29, 2026
Quick Overview
Given a sorted array of unique post IDs and an inclusive range [lower, upper] that contains them all, return the gaps as strings: a single ID like "7" or a span like "10->20".
Meta
November 29, 20260
0
0 solved
Given a sorted array of unique post IDs and an inclusive range [lower, upper] that contains them all, return the gaps as strings: a single ID like "7" or a span like "10->20".
This style of question appears when Meta interviewers want to see boundary handling under time pressure, for instance auditing which IDs are missing from an ingestion batch. They check off-by-one discipline at both ends of the range.
What the Interviewer Expects
- Handles the gap before the first element and after the last
- Uses sentinels (lower - 1 and upper + 1) to unify cases
- Formats single-value and multi-value gaps correctly
- Avoids off-by-one errors
- Handles an empty input array
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if the IDs arrive as an unsorted stream?
- Return the total count of missing IDs instead, in O(log n) using binary search.
- How would you merge missing ranges reported by many shards?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input array is ascending, unique, and every value lies in [lower, upper]. Output is a list of strings in ascending order. O(n) time....
High-Level Design
Treat lower - 1 as a virtual previous value and upper + 1 as a virtual final value. Then the only case is: for each consecutive pair (prev, cur), if cur - prev >= 2 the IDs from prev + 1 to `c...