PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Verkada
  • Coding & Algorithms
  • Software Engineer

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.

Find motion intervals above threshold

You are processing data from a single security camera. You are given: - A threshold value `T` (a real number). - An array of time-stamped motion readings. Each reading is a pair `[time, motion_level]`, where `time` is a strictly increasing integer timestamp (in seconds) and `motion_level` is a real number. Whenever `motion_level >= T`, the camera is considered **active**. Consecutive active readings (adjacent in the array, with no inactive reading between them) form one continuous active interval spanning from the time of the first active reading to the time of the last active reading in that group — even if there is a time gap between their timestamps. A reading with `motion_level < T` is inactive and belongs to no interval. Return a list of active time intervals `[start_time, end_time]` covering every maximal contiguous run of readings where `motion_level >= T`, in order. Example: - `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]]` Readings at times 11, 15, 17 have `motion_level >= 0.8`, forming `[11, 17]`. Readings at 27 and 36 form `[27, 36]`. All other readings are below threshold. Note on the boundary: the worked example treats a reading exactly equal to the threshold (0.8 at T=0.8) as active, so this challenge uses `motion_level >= T`.

Constraints

  • readings is sorted by time in strictly increasing order
  • 0 <= len(readings) (the list may be empty)
  • time is an integer; motion_level and T are real numbers
  • A reading equal to the threshold (motion_level == T) is treated as active

Examples

Input: ([[1, 0.4], [5, 0.2], [11, 0.9], [15, 0.9], [17, 0.8], [25, 0.5], [27, 0.8], [36, 0.9]], 0.8)

Expected Output: [[11, 17], [27, 36]]

Explanation: Times 11,15,17 are >= 0.8 -> [11,17]; times 27,36 are >= 0.8 -> [27,36]; everything else is below threshold.

Input: ([], 0.5)

Expected Output: []

Explanation: Empty input yields no intervals.

Input: ([[3, 0.9]], 0.5)

Expected Output: [[3, 3]]

Explanation: A single active reading is a degenerate interval [3,3].

Input: ([[1, 0.2], [2, 0.3], [3, 0.1]], 0.5)

Expected Output: []

Explanation: No reading reaches the threshold.

Input: ([[1, 0.9], [2, 0.9], [3, 0.9]], 0.5)

Expected Output: [[1, 3]]

Explanation: All three readings are active and contiguous -> one interval spanning first to last time.

Input: ([[1, 0.6], [2, 0.7], [3, 0.4], [4, 0.7], [5, 0.7]], 0.5)

Expected Output: [[1, 2], [4, 5]]

Explanation: An inactive reading at time 3 splits the active readings into two runs.

Input: ([[10, -0.5], [20, -0.2], [30, -0.8]], -0.3)

Expected Output: [[20, 20]]

Explanation: Negative thresholds work the same way: only -0.2 >= -0.3 is active.

Input: ([[1, 0.8], [2, 0.5], [3, 0.8]], 0.8)

Expected Output: [[1, 1], [3, 3]]

Explanation: Readings exactly equal to the threshold (0.8 at T=0.8) count as active; the inactive 0.5 between them splits them into two single-point intervals.

Hints

  1. Make a single left-to-right pass, tracking whether you are currently inside an active run.
  2. Open a run on the first active reading; the run's start_time is that reading's time. Keep updating the run's end_time to the latest active reading's time.
  3. Close (emit) the run the moment you hit an inactive reading, and remember to emit any run still open when the loop ends.

Time intervals where all cameras are active

This builds directly on the single-camera problem. Now you have **many** cameras. You are given: - A threshold value `T`. - A list `cameras`, where each element is one camera's array of `[time, motion_level]` readings (each sorted by strictly increasing time, as before). For each camera independently, compute its active intervals exactly as in Part 1 (`motion_level >= T`, consecutive active readings form one interval spanning first to last active time). Then return the time intervals during which **every** camera is simultaneously active — i.e. the intersection of all cameras' active-interval sets. Return the resulting overlapping intervals `[start_time, end_time]` in increasing order. If there is no time when all cameras are active together, return an empty list. Example: - `cameras = [[[1, 0.9], [3, 0.9], [5, 0.2], [7, 0.9], [9, 0.9]], [[1, 0.2], [3, 0.9], [5, 0.9], [7, 0.9], [9, 0.2]]]`, `T = 0.5` - Camera 0 active intervals: `[[1, 3], [7, 9]]`. Camera 1 active intervals: `[[3, 7]]`. - Overlap: `[1,3] ∩ [3,7] = [3,3]` and `[7,9] ∩ [3,7] = [7,7]` -> Output `[[3, 3], [7, 7]]`. **Follow-up (discuss):** if there are very many cameras, what is the bottleneck and how would you scale it? (Intersecting K sorted interval lists is O(total intervals); the cost is dominated by reading/parsing every reading once per camera. You can fold cameras pairwise and short-circuit as soon as the running intersection becomes empty.)

Constraints

  • Each camera's readings are sorted by strictly increasing time
  • cameras may be empty (return [])
  • Thresholding is inclusive: motion_level == T counts as active
  • Intervals are closed [start_time, end_time]; an intersection is non-empty when start <= end

Examples

Input: ([[[1, 0.4], [5, 0.2], [11, 0.9], [15, 0.9], [17, 0.8], [25, 0.5], [27, 0.8], [36, 0.9]]], 0.8)

Expected Output: [[11, 17], [27, 36]]

Explanation: A single camera reduces to Part 1: its own active intervals.

Input: ([[[1, 0.9], [2, 0.9], [3, 0.2], [4, 0.9]], [[1, 0.2], [2, 0.9], [3, 0.9], [4, 0.9]]], 0.8)

Expected Output: [[2, 2], [4, 4]]

Explanation: Cam0 active [[1,2],[4,4]], Cam1 active [[2,4]]; overlaps are [2,2] and [4,4].

Input: ([[[1, 0.9], [2, 0.9], [3, 0.9]], [[1, 0.9], [2, 0.9], [3, 0.9]]], 0.5)

Expected Output: [[1, 3]]

Explanation: Both cameras active over the whole span -> full overlap [1,3].

Input: ([[[1, 0.9], [2, 0.9]], [[1, 0.1], [2, 0.1]]], 0.5)

Expected Output: []

Explanation: The second camera is never active, so there is no common active time.

Input: ([], 0.5)

Expected Output: []

Explanation: No cameras -> empty result.

Input: ([[[1, 0.9], [5, 0.9], [9, 0.9]]], 0.5)

Expected Output: [[1, 9]]

Explanation: One camera, all active and contiguous -> [1,9] (time gaps inside an active run are kept).

Input: ([[[1, 0.9], [3, 0.9], [5, 0.2], [7, 0.9], [9, 0.9]], [[1, 0.2], [3, 0.9], [5, 0.9], [7, 0.9], [9, 0.2]]], 0.5)

Expected Output: [[3, 3], [7, 7]]

Explanation: Cam0 active [[1,3],[7,9]], Cam1 active [[3,7]]; intersecting gives [3,3] and [7,7].

Hints

  1. Reuse Part 1: turn each camera into its own list of active intervals first.
  2. To intersect two sorted, non-overlapping interval lists, walk both with two pointers; the overlap of [a1,b1] and [a2,b2] is [max(a1,a2), min(b1,b2)] and exists only when that low <= high.
  3. Fold the cameras one at a time: keep a running intersection and merge each new camera into it. If the running intersection ever becomes empty, you can stop early.
Last updated: Jun 26, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Merge Sorted Arrays In Place - Verkada (medium)
  • Find and Merge Camera Alert Intervals - Verkada (hard)
  • Find user who can access every camera - Verkada (medium)
  • Implement LRU and LFU caches - Verkada (medium)
  • Validate a 9×9 grid under constraints - Verkada (medium)