15% off all plans & roadmaps Use code
See plansLeetCode 268 · Solution & editorial
Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.
Missing Number is a Bit Manipulation Patterns problem, in the Bitwise XOR - Finding Single/Missing Number subpattern. The pattern covers XOR tricks, counting bits, power-of-two checks, and Hamming weight
Use XOR properties to find single number, missing number, and duplicates.
The reference solution runs in O(n) time and O(1) space.
Missing Number has been reported in interviews at Capital One, Amazon, Facebook, Apple, Microsoft, Oracle, Goldman Sachs, Cisco.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Missing Number is a Bit Manipulation Patterns problem, in the Bitwise XOR - Finding Single/Missing Number subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.