Kodebloc

Daily Coding Challenge

Solve today's challenge, earn streaks, and climb the leaderboard!

Share this challenge:
MEDIUM
Released: January 15, 2026 at 12:27 AM

Find Array Peak

Locate a 'peak' element within an integer array. A peak element is defined as an element that is strictly greater than its immediate neighbors.

Problem Statement

Given a 0-indexed integer array `nums`, you need to find and return the index of *any* peak element. An element `nums[i]` is a peak element if `nums[i] > nums[i-1]` and `nums[i] > nums[i+1]`. For elements at the boundaries, assume `nums[-1] = -infinity` and `nums[n] = -infinity` (where `n` is the length of the array). This means the first element is a peak if `nums[0] > nums[1]`, and the last element is a peak if `nums[n-1] > nums[n-2]`. You may assume that `nums[i] != nums[i+1]` for all valid `i`. The array will always contain at least one element. Your solution function will receive the array directly as input.

Example Test Cases

Input:
nums = [1, 2, 3, 1]
Output:
2
Explanation:

3 is a peak element because it's greater than its neighbors (2 and 1). Its index is 2.

Input:
nums = [1, 2, 1, 3, 5, 6, 4]
Output:
5
Explanation:

6 is a peak element (6 > 5 and 6 > 4). Its index is 5. Note that index 1 (value 2) is also a peak, but returning any valid peak index is acceptable.

Sign in to save your progress and compete on the leaderboard

Leaderboard

Find Array Peak

No submissions yet for this filter

Be the first to solve this challenge!