The Missing Number problem gives you an array containing n distinct numbers from the range [0, n]. Exactly one number is missing. Find it. This Missing Number coding problem is one of the most versatile easy-level questions, solvable with five different techniques: math (Gauss sum), XOR, hash table, sorting, or binary search. Mastering all approaches makes it an excellent teaching problem.
This problem is asked by Apple, Microsoft, Google, Amazon, Meta, Goldman Sachs, Bloomberg, Adobe, and nearly every major tech company. It's used as a screening question and as a discussion starter for multiple algorithmic approaches. Interviewers love asking candidates to list all possible solutions and explain trade-offs. The array, math, hash table, sorting, binary search, and bit manipulation interview pattern are all represented.
Multiple approaches:
arr[i] != i.Array: [3, 0, 1]. n=3. Expected sum = 3*4/2 = 6. Actual sum = 4. Missing = 6-4 = 2.
XOR approach: 0^1^2^3 ^ 3^0^1 = 2. (All matching pairs cancel, leaving 2.)
Always know at least two approaches for Missing Number: the math formula (O(1) space) and the XOR trick. Being able to explain why XOR works — duplicate values cancel because x ^ x = 0 and x ^ 0 = x — shows deep bit manipulation understanding. This problem is commonly extended: "find two missing numbers," "find the duplicate and missing number," etc. Practice all variants to prepare for follow-up questions.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Set Mismatch | Easy | Solve | |
| Fair Candy Swap | Easy | Solve | |
| Prison Cells After N Days | Medium | Solve | |
| Random Pick with Blacklist | Hard | Solve | |
| Intersection of Two Arrays | Easy | Solve |