Tap here to switch tabs
Problem
Ask
Submissions

Problem: Find Peak Element

med
30 min
Explore how to identify a peak element in an integer array where each peak is greater than its neighbors. This lesson helps you implement a modified binary search to solve the problem in O(log n) time. Understand how to handle edge cases with virtual boundaries and apply this pattern to similar search challenges efficiently.

Statement

You’re given a 0-indexed integer array nums. An index i is called a peak if nums[i] is strictly greater than its neighboring values (the elements immediately to its left and right, if they exist). Assume the array has virtual boundaries where nums[-1] = nums[n] = -∞, so the first and last elements can also be peaks.

Your task is to return the index of any one peak element (if there are multiple peaks, any valid peak index is acceptable), and your solution must run in O(logn)O(\log n) time.

Constraints:

  • 11 \leq nums.length 1000\leq 1000

  • 231-2^{31} \leq nums[i] 2311\leq 2^{31} - 1

  • nums[i] != nums[i + 1] for all valid i.

Tap here to switch tabs
Problem
Ask
Submissions

Problem: Find Peak Element

med
30 min
Explore how to identify a peak element in an integer array where each peak is greater than its neighbors. This lesson helps you implement a modified binary search to solve the problem in O(log n) time. Understand how to handle edge cases with virtual boundaries and apply this pattern to similar search challenges efficiently.

Statement

You’re given a 0-indexed integer array nums. An index i is called a peak if nums[i] is strictly greater than its neighboring values (the elements immediately to its left and right, if they exist). Assume the array has virtual boundaries where nums[-1] = nums[n] = -∞, so the first and last elements can also be peaks.

Your task is to return the index of any one peak element (if there are multiple peaks, any valid peak index is acceptable), and your solution must run in O(logn)O(\log n) time.

Constraints:

  • 11 \leq nums.length 1000\leq 1000

  • 231-2^{31} \leq nums[i] 2311\leq 2^{31} - 1

  • nums[i] != nums[i + 1] for all valid i.