FastPrepLongest Stationary Sensor Interval

Longest Stationary Sensor Interval

Wayve logoWayve● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

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 = 1return = [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 = 0return = [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

More Wayve problems

See Wayve hiring insights
public int[] longestStationaryInterval(int[] timestamps, int[] positions, int maxVariance) {
  // Write your code here.
}
timestamps[10,20,30,40,50]
positions[5,5,6,20,21]
maxVariance1
expected[10,30]
Checking account…