32/

directory
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: BSD-3-Clause

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

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL