FastPrepFind a Deterministic Local Minimum
Problems/Find a Deterministic Local Minimum

Find a Deterministic Local Minimum

Meta logoMeta● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meta onsite interview. The original report gives a binary search for a local minimum, and talks about one-element input and equal neighbors. It does not say what to do when there are several answers. We only added a fixed rule for moving down. Our version is about 94% the same as the reported question.

You are given a non-empty integer array nums. An index i is a local minimum when its value is no greater than each existing neighbor. Treat a missing neighbor outside the array as positive infinity.

Return the index chosen by this binary-search rule:

  1. Search the inclusive range [left,right] and use floor((left+right)/2) as mid.
  2. If nums[mid] is a local minimum, return mid.
  3. Otherwise, if the left neighbor is strictly smaller than nums[mid], continue in the left half.
  4. Otherwise continue in the right half.

This rule handles equal neighbors without requiring a strict local minimum.

Function

findLocalMinimum(nums: int[]) → int

Examples

Example 1

nums = [9,7,3,5,8]return = 2

The first midpoint is index 2, and 3 is no greater than either neighbor.

Example 2

nums = [4]return = 0

The only element has no existing neighbor and is therefore a local minimum.

Example 3

nums = [3,2,2,4]return = 1

Index 1 is the first midpoint and its value is no greater than either neighbor, including the equal value on its right.

Constraints

  • nums is non-empty.
  • Every value fits in a signed 32-bit integer.
  • Equal adjacent values are allowed.
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public int findLocalMinimum(int[] nums) {
        // Write your code here.
    }
}
Checking account…