The number that is not there
Reported in interviews at (where)
nums holds n different whole numbers, all taken from 0 to n (that range has n + 1 numbers), in any order. Exactly one number from the range is missing.
Return it. Can you do it with no extra list, in one pass?
- Input
nums = [4,2,0,1]- Output
3
n = 4, so the range is 0 to 4, and 3 is the one not in the list.
- Input
nums = [1]- Output
0
n = 1: the range is 0 and 1.
Limits
1 <= n == nums.length <= 1000000 <= nums[i] <= nAll values in nums are different.
Hints
Hint 1
The numbers 0 to n add up to n(n + 1) / 2.
Hint 2
Or XOR every index and every value together: pairs cancel.
Where this was reported
- HSBC, Technology off-campus interview, 2023 (GeeksforGeeks)
- Mastercard, SDE on-campus interview, 2024 (GeeksforGeeks)
Our own problem on the task these candidates describe; the wording, examples and tests are InternDoor’s.
Run your code to check it on the examples. Submit runs every hidden test.

