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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
XOR
Arithmetic series
Constant space
Overflow
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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:

  1. Sum: the full range sums to n(n+1)/2n(n+1)/2; 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...

Submit Your Answer
Markdown supported