Find the Missing Story ID in a Shuffled Upload Range
Last updated: November 29, 2026
Quick Overview
A batch of n story uploads should have IDs 0 through n, but exactly one is missing from the shuffled list of n IDs. Return the missing ID without sorting and with O(1) extra space.
Meta
November 29, 20260
0
0 solved
A batch of n story uploads should have IDs 0 through n, but exactly one is missing from the shuffled list of n IDs. Return the missing ID without sorting and with O(1) extra space.
Meta screens like quick math or bit puzzles that test whether you see a closed-form or XOR trick instead of sorting. Expect the interviewer to ask about overflow in other languages and which approach you would pick.
What the Interviewer Expects
- Offer sorting and hash-set baselines with their costs
- Give the Gauss sum formula approach
- Give the XOR approach and compare it with the sum approach
- Mention overflow concerns for fixed-width integers
- Handle missing 0 and missing n
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 two IDs are missing?
- What if the IDs start at an arbitrary offset k instead of 0?
- How would you find a duplicated ID instead of a missing one?
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: list ids of length n with distinct values in [0, n]. Exactly one value in that range is absent. Output: the absent value. We want O(n) time and O(1) extra space, without mutating the input. S...
High-Level Design
Two equivalent O(1)-space ideas:
- Sum: the full range sums to ; subtract the actual sum. In Python there is no overflow, but in Java or C++ the sum can overflow 32 bits for n around 6...