Find Local Maxima in Sensor Data
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 September 2026, and the story about sensor streams is just dressing. It's an array problem: for each index, check whether the localArea elements on each side strictly decrease away from it. If your OA invite lands in the next few days, this is the kind of question where the naive loop looks fine until the inputs get big. StealthCoder sits invisibly on your screen as a safety net if you blank on the optimization. Know the trick first and you probably won't need it.
The problem
Imagine that you are working on a model to predict anomalies in temperature fluctuations. The data is collected in continuous streams from sensors, which you need to clean to develop an initial set of test data. Given an array of integers rawData representing temperature values, and an integer localArea, find every local maximum within rawData. rawData[i] is considered to be a local maximum if, starting from rawData[i], localArea numbers to the left and localArea numbers to the right both form strictly decreasing subsequences. If there are less than localArea numbers to the left (or to the right) of rawData[i], take all numbers on that side into account when computing the local maximum. In other words, rawData[i] is a local maximum if both of the following conditions are true: rawData[i] > rawData[i + 1] > rawData[i + 2] >... > rawData[i + localArea] or rawData[i] > rawData[i + 1] > rawData[i + 2] >... > rawData[length(rawData) - 1] rawData[i] > rawData[i - 1] > rawData[i - 2] >... > rawData[i - localArea] or rawData[i] > rawData[i - 1] > rawData[i - 2] >... > rawData[0] Return an array of integers containing the 0-based indices of all local maximums within rawData. Elements of this array should be sorted in ascending order. Function findLocalMaxima(rawData: int[], localArea: int) → int[] Examples Example 1 rawData = [2, 10, 4, 3, 11, 5, 2, 6, 12, 3, 2] localArea = 2 return = [1, 8] For rawData = [2, 10, 4, 3, 11, 5, 2, 6, 12, 3, 2] and localArea = 2, the output should be solution(rawData, localArea) = [1, 8]. Explanation: rawData[1] = 10 is a local maximum. The remainder of the source explanation is cropped or obscured in the captured image. Constraints FastPrep execution-adapter constraints (not shown in the source image): rawData is non-empty. localArea is positive. Every element of rawData is an integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The brute force checks localArea elements left and right for every index. That's O(n * localArea), and it blows up when both are large. The trick is precomputing run lengths. Build left[i], the count of consecutive strictly decreasing steps going leftward from i (so left[i] = left[i-1] + 1 if rawData[i-1] < rawData[i], else 0). Build right[i] the same way from the other end. Index i is a local maximum if left[i] >= min(localArea, i) and right[i] >= min(localArea, n-1-i). That's O(n) with two passes and one collection pass. Pitfalls: using non-strict comparisons, forgetting the boundary rule where fewer than localArea neighbors exist, and returning indices out of order. Collect in a forward loop and they come out sorted. If you freeze mid-OA, StealthCoder can surface this run-length approach live, but you should be able to write it yourself.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Find Local Maxima in Sensor Data 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass TikTok's OA.
TikTok reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find Local Maxima in Sensor Data FAQ
What's the trick in the TikTok Find Local Maxima problem?+
Precompute how far a strictly decreasing run extends away from each index, once from the left and once from the right. Then each index is checked in O(1) against localArea. That turns an O(n * localArea) scan into O(n) total.
How do I handle indices near the array edges?+
Cap the required run length by the number of elements available. For index i, you need left run >= min(localArea, i) and right run >= min(localArea, n-1-i). At index 0, the left requirement is 0, so only the right side matters.
Does equality break a local maximum here?+
Yes. The comparisons are strictly decreasing, so equal neighbors fail the check. When building run lengths, reset the counter to 0 on any equal or increasing step. Using >= instead of > is the most common wrong-answer bug.
How hard is this problem really?+
It's easy to medium. The logic is simple, but the brute force can time out on large inputs. If you know prefix-style run-length arrays, you can finish it fast. The edge-boundary rule is where most people lose points.
How do I prep for this in 48 hours?+
Write the two-pass run-length solution from scratch twice. Test with localArea larger than the array, a single-element array, and flat plateaus. Then try similar array scans using left and right precomputation, like trapping rain water, to build the habit.