The Summit Element

MediumAcc. 92.1%
+35 XP 15

Looking for Peaks

An element is a peak if it is not smaller than its neighbors (for the first and last, only one neighbor).

The Assignment

Your function receives nums.

  1. Iterate through the array.
  2. If the current element is a peak, print it and exit.

01EXAMPLE 1

Input[1, 2, 3, 1]
Output3

Explanation: 3 > 2 and 3 > 1.

Constraints

  • Linear scan is acceptable.
ArraysSearching
JavaScript
Loading...
2 Hidden

Input Arguments

nums[1,2,3,1]

Expected Output

3

Click RUN to test your solution