Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Binary search

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Binary search

Find Peak Element

intermediatelayer B6 · Binary search5 tests

A peak is an element strictly greater than both of its neighbours. Given an array nums in which no two adjacent values are equal, return the index of any peak.

  • Treat the positions just outside the array as -Infinity, so the first and last elements only need to beat their single real neighbour
  • Several peaks may exist — returning any one of them is correct
  • Must run in O(log n), so scanning for the maximum is not acceptable

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen