Find Any Local Minimum with Iterative Binary Search

Quick Overview

Find the index of any strict local minimum in a nonempty array whose adjacent values differ, using an iterative logarithmic-time algorithm. The task tests search invariants, boundary-as-infinity semantics, singleton and monotone arrays, and correctness when several indices are valid.

Find Any Local Minimum with Iterative Binary Search

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

# Find Any Local Minimum with Iterative Binary Search Given a nonempty integer array `numbers`, return the index of any local minimum. An index `i` is a local minimum when its value is strictly smaller than each neighbor that exists. Treat the missing neighbor beyond either boundary as positive infinity. Adjacent elements are guaranteed to be different. Your implementation must be iterative and run in `O(log n)` time. ## Function Signature ```python def find_local_minimum(numbers: list[int]) -> int: ... ``` ## Constraints - `1 <= len(numbers) <= 1_000_000` - `numbers[i] != numbers[i + 1]` for every valid adjacent pair. - `-1_000_000_000 <= numbers[i] <= 1_000_000_000`. - If multiple local minima exist, return any valid index. ## Examples ```text Input: numbers = [9, 7, 3, 5, 8] Output: 2 ``` ```text Input: numbers = [1, 4, 3] Output: 0 or 2 ``` ```text Input: numbers = [6] Output: 0 ```

Quick Answer: Find the index of any strict local minimum in a nonempty array whose adjacent values differ, using an iterative logarithmic-time algorithm. The task tests search invariants, boundary-as-infinity semantics, singleton and monotone arrays, and correctness when several indices are valid.

|Home/Coding & Algorithms/Meta
Meta logo
Meta
Mar 2, 2026, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
0
0

Given a nonempty integer array numbers, return the index of any local minimum. An index i is a local minimum when its value is strictly smaller than each neighbor that exists. Treat the missing neighbor beyond either boundary as positive infinity.

Adjacent elements are guaranteed to be different. Your implementation must be iterative and run in O(log n) time.

Function Signature

def find_local_minimum(numbers: list[int]) -> int:
    ...

Constraints

  • 1 <= len(numbers) <= 1_000_000
  • numbers[i] != numbers[i + 1] for every valid adjacent pair.
  • -1_000_000_000 <= numbers[i] <= 1_000_000_000 .
  • If multiple local minima exist, return any valid index.

Examples

Input: numbers = [9, 7, 3, 5, 8]
Output: 2
Input: numbers = [1, 4, 3]
Output: 0 or 2
Input: numbers = [6]
Output: 0

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...