Problem · Array
Find All Local Peaks
Learn this problemProblem statement
Given an integer array nums, find every local peak.
An element nums[i] is a local peak when it has both an immediate left neighbor and an immediate right neighbor, and nums[i] > nums[i - 1] and nums[i] > nums[i + 1].
Return the values of all local peaks in their original left-to-right order. The first and last elements are never local peaks because they do not have two neighbors. If no local peak exists, return an empty array.
Function
findAllLocalPeaks(nums: int[]) → int[]Examples
Example 1
nums = [1, 3, 2, 4, 1]return = [3, 4]The value 3 is greater than 1 and 2, and the value 4 is greater than 2 and 1. They appear in that order in nums.
Example 2
nums = [5, 4, 3, 2, 1]return = []No element with two neighbors is greater than both of them. The boundary values 5 and 1 are not eligible.
More Tiktok problems
- Concatenate Digit-wise SumsOA · Seen Aug 2026
- Count 2x2 Submatrices by Black CellsOA · Seen Aug 2026
- Count House Segments After DestructionOA · Seen Aug 2026
- Debugger Breakpoint ActionsOA · Seen Aug 2026
- Distribution Center Package AllocationOA · Seen Aug 2026
- Minimum Height Difference Between Distant PeaksOA · Seen Aug 2026
- Minimum Operations for Stepwise StructuresOA · Seen Aug 2026
- Rating Level After ChangesOA · Seen Aug 2026