Find motion intervals above threshold
Company: Verkada
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
You are processing data from a single security camera.
You are given:
- A threshold value `T` (a real number).
- A vector (array) of time-stamped motion readings. Each reading is a pair `[time, motion_level]`, where:
- `time` is a strictly increasing integer timestamp (in seconds),
- `motion_level` is a real number.
Whenever `motion_level > T`, we consider the camera to be "active". Consecutive active readings form a continuous active interval from the time of the first active reading to the time of the last active reading in that group.
Assume:
- The input vector is sorted by `time` in strictly increasing order.
- If two active readings are adjacent in the array (with no inactive reading between them), they belong to the same active interval, even if there is a time gap between their timestamps.
- If a reading is inactive (`motion_level <= T`), it does not belong to any active interval.
Return a list of active time intervals `[start_time, end_time]` covering all maximal contiguous segments of readings where `motion_level > T`.
Example:
- Input:
- `readings = [[1, 0.4], [5, 0.2], [11, 0.9], [15, 0.9], [17, 0.8], [25, 0.5], [27, 0.8], [36, 0.9]]`
- `T = 0.8`
- Output:
- `[[11, 17], [27, 36]]`
Explanation:
- Readings at times 11, 15, 17 have `motion_level > 0.8`, so they form one interval `[11, 17]`.
- Readings at times 27 and 36 have `motion_level > 0.8`, forming interval `[27, 36]`.
- All other readings have `motion_level <= 0.8` and are ignored.
Implement a function that takes the readings and threshold and returns the list of such intervals.
Quick Answer: This question evaluates understanding of time-series data processing and interval detection, focusing on grouping timestamped motion readings that exceed a numeric threshold and managing contiguous active segments.