FastPrepFind All Local Peaks
Problems/Find All Local Peaks

Find All Local Peaks

TikTok logoTikTok● EasyINTERNOA
QuestionFunctionExamples

Problem statement

Source note: A TikTok Intern OA report last seen on 2026-08-05 describes scanning an array and collecting every element that is strictly greater than both immediate neighbors. This differs from Find Peak Element, which returns any one peak index in logarithmic time; that existing problem was used only as a nearby reference, not as evidence that the TikTok prompt was identical. Because the report omits the original callable signature, examples, numeric bounds, and an explicit endpoint convention, this judged version considers only internal elements and returns their values from left to right. The reported core behavior is preserved at about 90% confidence.

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

  • Minimum Cost of Every K-Capable Model SetOA · Seen Nov 2026
  • Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Oct 2026
  • Next Greater Indices and Maximum GapPHONE SCREEN · Seen Oct 2026
All TikTok interview questionsSee TikTok hiring insights
Saved
class Solution {
    public int[] findAllLocalPeaks(int[] nums) {
        // write your code here
    }
}
Checking account…