bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 162. Find Peak Element

162. Find Peak Element

Leetcode Solutions

Iterative Binary Search

  1. Initialize two pointers, left and right, to the start and end of the array respectively.
  2. Enter a loop that continues while left is less than right.
  3. Calculate the mid index as the average of left and right.
  4. If mid is not the last element and nums[mid] is less than nums[mid + 1], move the left pointer to mid + 1 (ascending slope).
  5. Else, move the right pointer to mid (descending slope or peak).
  6. When left equals right, the search space is narrowed down to one element, which is the peak. Return left.
UML Thumbnail

Linear Scan

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...