directory
Version:
v0.1.0
Opens a new window with list of versions in this module.
Published: Sep 24, 2026
License: BSD-3-Clause
Opens a new window with license information.
README
¶
Name
32 - find local maxima
Description
Problem
Given an array, find local maxima.
Definition: local maxima is a value that is greater than its immediate neighbors.
Assumptions:
- the immediate neighbors are guaranteed to be non-equal numbers
Example
Input: [4 5 1 3 2]
Output: valid answers are 5 or 3.
Solution
Details
Use binary search. Check neighbors to detect the slope and move in corresponding
direction.
Complexity:
- time: O(log(n))
- space: O(1)
Directories
¶
Click to show internal directories.
Click to hide internal directories.