Merge Camera Motion Events Into Timeline Segments

Last updated: November 29, 2026

Quick Overview

Given a list of motion detections from one camera as (start, end) second offsets in any order, merge them into the shaded segments shown on the playback timeline, bridging quiet gaps of at most `gap` seconds.

Verkada
Coding & Algorithms
Software Engineer
Verkada
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a list of motion detections from one camera as (start, end) second offsets in any order, merge them into the shaded segments shown on the playback timeline, bridging quiet gaps of at most `gap` seconds.

Verkada's Command web app draws motion bars under every camera's scrubber, and the backend has to turn noisy edge detections into a few clean segments. A phone screen uses this to check that you can sort, merge and reason about inclusive boundaries quickly and cleanly.

What the Interviewer Expects
  • Sorts by start before merging and explains why
  • Handles the gap tolerance correctly, including gap = 0 and touching intervals
  • Covers fully contained intervals without shrinking the merged end
  • Returns an empty list for empty input
  • States O(n log n) time and O(n) output space
Key Topics to Cover
interval merging
sorting
boundary conditions
streaming aggregation
video timeline
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Detections now arrive as a live stream in roughly sorted order. How do you emit segments incrementally?
  • How would you merge segments across 50 cameras into one site-wide activity bar?
  • The UI zooms out to a week. How would you downsample segments so the client does not receive millions?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list of (start, end) with start <= end, unsorted, possibly overlapping. Two intervals belong to the same segment when the next start is at most gap seconds after the current segment's end...

High-Level Design

Sort by start. Walk once, keeping the last merged segment. If the next interval starts within gap of that segment's end, extend the end to max(end, e); otherwise start a new segment. The max mat...


Submit Your Answer
Markdown supported

Related Questions