← Questions
Find a local minimum in an array
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Uber's coding round and at Meta, last asked Apr 2026. It tests binary-search.
Given an array of distinct integers, return the index of any local minimum: an element strictly smaller than its neighbours. Positions just outside the array count as positive infinity, so an end element only needs to beat its one neighbour. A linear scan works; then do it in O(log n).
Interface
Unless you agree on a different interface with the interviewer, assume:
-
local_min(nums: list[int]) -> int— the 0-based index of any local minimum.
Example
local_min([9, 6, 3, 14, 5, 7, 4]) -> 2 (3), 4 (5) or 6 (4) are all valid
local_min([1, 2, 3]) -> 0
local_min([3, 2, 1]) -> 2
local_min([4]) -> 0
Constraints
-
1 <= len(nums) <= 200,000; all values distinct.
Clarifying questions
- Are the values distinct? (With duplicates the strict definition may have no answer.)
- How do the ends behave: compare only with one neighbour?
- Is any local minimum acceptable, or a specific one?
What a strong answer covers
- Why one always exists: with infinite boundaries, the global minimum is a local minimum.
- Binary search on the slope: look at
midandmid + 1; ifnums[mid] < nums[mid + 1], a local minimum lies in[lo, mid], otherwise in[mid + 1, hi].O(log n)time,O(1)space. - The invariant that makes the discarded half safe, and the loop condition that avoids an off-by-one.
- Tests: one element, strictly increasing, strictly decreasing, the minimum in the middle.
Follow-ups
- The same in a 2D grid: find a cell smaller than its four neighbours in
O(n)for ann x ngrid. - Allow duplicates and use the non-strict definition (no larger than its neighbours).
- Find a peak element instead.
Where it's asked
- Uber · Coding · Last asked Apr 202660 min · Two rounds; one is often object-oriented design (a parking lot, a meeting scheduler, an expression evaluator) · No AI, except a newer AI-assisted debugging round in some senior loops
- Meta · Technical phone screen · Last asked Jul 202545 min · Two coding problems in CoderPad, about 20 minutes each · Usually no AI; some newer screens are AI-assisted
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding

