Dashboard
LC #704
Binary Search
Pattern · ?AmazonGoogleMicrosoftApple
Problem
Given a sorted array and a target, return the index of the target or -1.
Constraints
- 1 ≤ n ≤ 10⁴
- -10⁴ ≤ nums[i], target ≤ 10⁴
- All values in nums are unique
- nums is sorted in ascending order
- O(log n) runtime required
Example
- Input
- nums = [-1, 0, 3, 5, 9, 12], target = 9
- Output
- 4
- Why
- 9 is at index 4
Spot the pattern
Which pattern cracks it?
Hints
One at a time