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.
- Iterate through the array.
- If the current element is a peak, print it and exit.
01EXAMPLE 1
Input
[1, 2, 3, 1]Output
3Explanation: 3 > 2 and 3 > 1.
Constraints
- Linear scan is acceptable.
ArraysSearching
JavaScriptSystem handles I/O — write your function only
Loading...
2 Hidden
Input Arguments
nums[1,2,3,1]
Expected Output
3
Click RUN to test your solution