PracHub
QuestionsLearningGuidesInterview Prep
|Home/Coding & Algorithms/Serval

Find Shared Motion Periods Across Camera Streams

Last updated: Jul 28, 2026

Quick Overview

Convert thresholded camera readings into closed active periods, then report the periods shared by every stream. Account for isolated readings, timestamp gaps, empty camera sets, point intersections, non-mutating inputs, and the demands of out-of-order or unbounded live data.

  • medium
  • Serval
  • Coding & Algorithms
  • Software Engineer

Find Shared Motion Periods Across Camera Streams

Company: Serval

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Find Shared Motion Periods Across Camera Streams A camera emits readings `(timestamp, intensity)` sorted by strictly increasing timestamp. Intensity is between 0 and 1. A reading is active when its intensity is at least a supplied threshold. Implement both parts. ### Part A - Active Periods for One Camera Consecutive active readings form one closed period whose start and end are the first and last active timestamps. An inactive reading ends the current period. Timestamp gaps alone do not split a period. ```text active_periods(readings, threshold) -> list[[start, end]] ``` Example: ```text readings = [ [1, 0.4], [5, 0.2], [11, 0.9], [15, 0.9], [17, 0.8], [20, 0.3], [27, 0.9], [31, 1.0], [36, 0.8] ] threshold = 0.8 result = [[11, 17], [27, 36]] ``` A single isolated active reading produces `[timestamp, timestamp]`. ### Part B - Periods Shared by Every Camera Given a list of camera streams, return the closed time intervals during which every camera is active. You may reuse Part A for each stream, then intersect the resulting sorted, disjoint interval lists. ```text shared_active_periods(camera_streams, threshold) -> list[[start, end]] ``` Example: ```text camera_streams = [ [[1, 0.9], [4, 0.9], [6, 0.1], [9, 1.0]], [[2, 0.8], [5, 0.8], [7, 0.2], [9, 0.9]] ] threshold = 0.8 per-camera periods = [[[1, 4], [9, 9]], [[2, 5], [9, 9]]] result = [[2, 4], [9, 9]] ``` ### Constraints - Each stream contains at most 100000 readings. - `0 <= len(camera_streams) <= 1000`. - For no cameras, return an empty list. - Periods are closed; an intersection at one timestamp is retained. - Inputs must not be mutated. ### Hints - Part A is one linear scan with an optional open-period start. - Intersect two sorted interval lists with two pointers, then fold that operation across cameras. - Stop early if an intermediate intersection becomes empty. ### Discussion Extensions - State complexity in terms of total readings and generated intervals. - How would out-of-order readings change the design? - How would you process unbounded live streams while bounding memory?

Quick Answer: Convert thresholded camera readings into closed active periods, then report the periods shared by every stream. Account for isolated readings, timestamp gaps, empty camera sets, point intersections, non-mutating inputs, and the demands of out-of-order or unbounded live data.

|Home/Coding & Algorithms/Serval

Find Shared Motion Periods Across Camera Streams

Serval logo
Serval
Jul 12, 2026, 12:00 AM
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
0
0

Find Shared Motion Periods Across Camera Streams

A camera emits readings (timestamp, intensity) sorted by strictly increasing timestamp. Intensity is between 0 and 1. A reading is active when its intensity is at least a supplied threshold.

Implement both parts.

Part A - Active Periods for One Camera

Consecutive active readings form one closed period whose start and end are the first and last active timestamps. An inactive reading ends the current period. Timestamp gaps alone do not split a period.

active_periods(readings, threshold) -> list[[start, end]]

Example:

readings = [
  [1, 0.4], [5, 0.2], [11, 0.9], [15, 0.9], [17, 0.8],
  [20, 0.3], [27, 0.9], [31, 1.0], [36, 0.8]
]
threshold = 0.8

result = [[11, 17], [27, 36]]

A single isolated active reading produces [timestamp, timestamp].

Part B - Periods Shared by Every Camera

Given a list of camera streams, return the closed time intervals during which every camera is active. You may reuse Part A for each stream, then intersect the resulting sorted, disjoint interval lists.

shared_active_periods(camera_streams, threshold) -> list[[start, end]]

Example:

camera_streams = [
  [[1, 0.9], [4, 0.9], [6, 0.1], [9, 1.0]],
  [[2, 0.8], [5, 0.8], [7, 0.2], [9, 0.9]]
]
threshold = 0.8

per-camera periods = [[[1, 4], [9, 9]], [[2, 5], [9, 9]]]
result = [[2, 4], [9, 9]]

Constraints

  • Each stream contains at most 100000 readings.
  • 0 <= len(camera_streams) <= 1000 .
  • For no cameras, return an empty list.
  • Periods are closed; an intersection at one timestamp is retained.
  • Inputs must not be mutated.

Hints

  • Part A is one linear scan with an optional open-period start.
  • Intersect two sorted interval lists with two pointers, then fold that operation across cameras.
  • Stop early if an intermediate intersection becomes empty.

Discussion Extensions

  • State complexity in terms of total readings and generated intervals.
  • How would out-of-order readings change the design?
  • How would you process unbounded live streams while bounding memory?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Serval•More Software Engineer•Serval Software Engineer•Serval Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

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

Product

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

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.