Longest Stationary Sensor Interval
Reported by candidates from Wayve's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Wayve reportedly asked this one in September 2026, and the input size is the first thing to read. With up to 2000 samples, a naive approach that recomputes variance from scratch for every interval turns into O(n^3), which is the trap. The real task is finding the longest contiguous window where population variance stays under a threshold, using exact integer math. If you've got an OA invite for this, the trick is prefix sums, not clever DP. StealthCoder is the safety net if your head goes blank mid-assessment, but the pattern is simple once you see it.
The problem
Sensor samples have strictly increasing timestamps and one-dimensional integer positions. A contiguous interval is stationary when its population variance is at most maxVariance. Return the start and end timestamps of the stationary interval containing the most samples. Break ties by the smaller start index. Compare variance exactly using count × sumSquares - sum² <= maxVariance × count². Function longestStationaryInterval(timestamps: int[], positions: int[], maxVariance: int) → int[] Examples Example 1 timestamps = [10,20,30,40,50] positions = [5,5,6,20,21] maxVariance = 1 return = [10,30] The first three positions have variance below one; adding 20 exceeds the threshold. Example 2 timestamps = [1,2,3] positions = [0,10,0] maxVariance = 0 return = [1,1] Only single-sample intervals have zero variance, so the earliest one wins. Constraints 1 <= timestamps.length = positions.length <= 2000 Timestamps are strictly increasing. |positions[i]| <= 10000 0 <= maxVariance <= 100000000
Reported by candidates. Source: FastPrep
Pattern and pitfall
Build two prefix arrays: one for sums of positions and one for sums of squares. Then any interval [i, j] gives count, sum, and sumSquares in O(1). Check the exact inequality count * sumSquares - sum^2 <= maxVariance * count^2 with no floating point. Loop over all O(n^2) pairs, which is about 2 million checks at n=2000. That's fine. Track the max length, and on ties keep the smaller start index by only updating on strictly greater length while iterating starts in ascending order. Return timestamps at the start and end indices, not the indices themselves. Watch overflow: sumSquares can reach 2000 * 10^8 = 2*10^11, and multiplied by count it's about 4*10^14, so use 64-bit. maxVariance * count^2 can hit 4*10^14 too. If you freeze on the live OA, StealthCoder can hand you the prefix-sum skeleton while you verify the tie-break.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Longest Stationary Sensor Interval 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 passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Wayve's OA.
Wayve reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Longest Stationary Sensor Interval FAQ
What's the trick in the Wayve stationary sensor interval problem?+
Prefix sums of positions and positions squared. They let you compute count, sum, and sum of squares for any interval in constant time. Then you test the exact integer variance inequality for every pair. No sliding window needed, since variance isn't monotonic when you extend the interval.
Why can't I just use a sliding window or two pointers?+
Variance isn't monotonic as you shrink or grow a window. Adding a sample can lower variance in some cases, and removing one can raise it. So a two-pointer shrink rule can skip valid intervals. With n at most 2000, checking all pairs is safe and correct.
Do I need floating point for the variance comparison?+
No, and you shouldn't use it. The problem gives the exact inequality: count * sumSquares - sum^2 <= maxVariance * count^2. Everything is integers. Use 64-bit types because the products reach roughly 4*10^14, which overflows 32-bit ints.
How do I handle ties and the return format?+
Iterate start indices in ascending order and only update the best when an interval is strictly longer. That keeps the smaller start on ties. Return the timestamps at the start and end indices, not the indices. Example 2 returns [1,1] for that reason.
How should I prepare for this in 48 hours?+
Write the prefix-sum setup from memory, then code the O(n^2) pair loop and test both examples by hand. Add edge cases: n=1, maxVariance=0, and all-equal positions. Check your integer types for overflow. That covers nearly everything this problem can throw at you.