easyBit ManipulationMicrosoft
Missing Spot Finder
A librarian has shelf slots 0..n but one is empty; find the missing slot number.
Given an array of n distinct numbers in [0, n], return the missing one.
Choose approach
3
00
11
2Mapstate
x→3
1/5
Narrationstep 1 of 5
Seed x = n = 3.
Variables
x=3
How to think about it
- Sum formula also works (n(n+1)/2 - sum(nums)).
- XOR avoids overflow.
Edge cases to catch in interview
- Missing 0.
- Missing n.
Examples
Example 1
2{"values":[0,1]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed