Dashboard
LC #162
Find Peak Element
Pattern · ?GoogleMetaMicrosoftAmazonBloomberg
Problem
A peak element is one that is strictly greater than its neighbors. Find any peak in O(log n).
Constraints
- 1 ≤ nums.length ≤ 1000
- -2³¹ ≤ nums[i] ≤ 2³¹-1
- nums[-1] = nums[n] = -∞ (edges are valleys)
- O(log n) required
Example
- Input
- nums = [1, 2, 3, 1]
- Output
- 2
- Why
- nums[2] = 3 is a peak since nums[1] < nums[2] > nums[3]
Spot the pattern
Which pattern cracks it?
Hints
One at a time