Find All Local Peaks
Reported by candidates from TikTok's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
TikTok reported this one in August 2026, and it's a quiet little problem. Find All Local Peaks looks too easy to be an OA question, which is exactly why people rush it and lose points. The whole thing hinges on a plain array and a single pass, no fancy structure needed. You compare each interior element to its two neighbors and collect the winners in order. If your head goes blank on the boundary rules, StealthCoder is the safety net running invisibly during the live OA. Most candidates won't need it here, but the edge cases are where the hidden tests bite.
The problem
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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that there isn't one. Loop i from 1 to n-2, check nums[i] > nums[i-1] and nums[i] > nums[i+1], and append nums[i] to a result list. That's O(n) time and O(1) extra space beyond the output. The pitfalls are all boundary stuff. Don't start at index 0 or run to the last index, or you'll hit out-of-range errors or wrongly count the ends. The comparison must be strict, so plateaus like [1, 3, 3, 2] produce no peak. Return values, not indices, since the problem asks for the values. Arrays shorter than 3 should return an empty array, and your loop bounds handle that naturally. If you freeze on any of this during the live OA, StealthCoder can hand you the clean loop so you just verify it against the two examples.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Find All Local Peaks cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass TikTok's OA.
TikTok reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find All Local Peaks FAQ
How hard is Find All Local Peaks really?+
Easy. It's a single pass with two comparisons per element. The difficulty is in not tripping on boundaries and strict inequality. If you can write a for loop from 1 to n-2, you can finish this in a few minutes and spend the rest on edge cases.
What's the trick to this TikTok problem?+
There's no hidden trick. Scan interior indices only, compare each value to its left and right neighbor, and push qualifying values into a result list. The only real work is getting the loop bounds right and using strict greater-than.
Do I return indices or values?+
Values. The problem says to return the values of all local peaks in original left-to-right order. Example 1 returns [3, 4], not [1, 3]. Mixing this up is a common way to fail otherwise correct code.
What edge cases should I test before submitting?+
Test an array with fewer than 3 elements, a strictly decreasing array like Example 2, equal neighbors such as [1, 3, 3, 2], and consecutive peaks like [1, 3, 2, 4, 1]. Also confirm the first and last elements are never included.
How do I prepare for this in 48 hours?+
Write the loop from memory twice, then run it on both examples by hand. Spend the remaining time on similar array-scan problems with neighbor comparisons. This pattern is simple, so clean boundary handling matters more than any new concept.