Find the Single Missing Ticket ID in a Shuffled Range
Last updated: November 29, 2026
Quick Overview
An array contains n distinct integers taken from the range 0 to n with exactly one value missing, in arbitrary order; return the missing value using O(1) extra space.
0
0
0 solved
An array contains n distinct integers taken from the range 0 to n with exactly one value missing, in arbitrary order; return the missing value using O(1) extra space.
A short Google screen question that tests whether you can reach a constant-space answer and reason about overflow. Interviewers often ask for two different approaches (sum and XOR) and expect you to compare them.
What the Interviewer Expects
- Gives a simple hash set solution and notes its O(n) space
- Derives the arithmetic sum approach and discusses overflow in fixed-width languages
- Presents the XOR approach and explains why pairs cancel
- Confirms the answer can be 0 or n
- Keeps the solution to one pass
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? Find both in O(1) space.
- What if the array is sorted; can you beat O(n)?
- What if the numbers are stored on disk and do not fit in memory?
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 of n distinct ints, each in [0, n], one value absent.
- Output: the absent value.
- Constraints: O(n) time, O(1) extra space, input may not be modified....
High-Level Design
XOR every index 0..n with every element. Each present value appears twice (once as an index or n, once as a value) and cancels, since x ^ x == 0 and XOR is commutative. The only survivor is the miss...