Missing Number
Given an array containing n distinct numbers in range [0, n] Find the one missing number Example: [3,0,1] => 2 (range is 0,1,2,3 - missing 2)
Missing Number is really a boundary-finding problem, even if it doesn't look like it at first. It's a great warm-up that builds boundary precision without a ton of moving parts. Interviewers care more about airtight boundaries than speed here.
Examples
You write
missing_number(nums: List[int])
Example 1
- Input
- nums = [3,0,1]
- returns
- 2
Example 2
- Input
- nums = [0,1]
- returns
- 2
The pattern behind it
Arrays & Hashing
I reach for it when
- You catch yourself scanning the array again for every element.
- The problem asks about duplicates, pairs, counts or groups.
Say this before you type. Say what the key is and what the value remembers, before you write the loop.
All 127 Arrays & Hashing problemsBinary Search
I reach for it when
- The input is sorted, or sorted and then rotated.
- You want a boundary: the first or last place something is true.
Say this before you type. Say the yes-or-no question, and which side each answer throws away.
All 19 Binary Search problems
Meet Coco
Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.