Answer How Many Live Streams Were Running at Each Query Time

Last updated: November 29, 2026

Quick Overview

Given the [start, end) times of n Live streams and a list of q query timestamps, return for each query how many streams were live at that moment.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given the [start, end) times of n Live streams and a list of q query timestamps, return for each query how many streams were live at that moment.

A counting-with-binary-search problem in the style of a Meta technical screen, framed around a Live dashboard that lets an analyst scrub to any moment. The interviewer looks for the insight that the count equals starts at or before t minus ends at or before t, which avoids per-query scans.

What the Interviewer Expects
  • Starts from the O(n * q) brute force and states its cost
  • Separates starts and ends into two sorted arrays
  • Uses bisect_right on both to count in O(log n) per query
  • Gets the half-open boundary right: a stream ending at t is not live at t
  • Mentions an offline sweep alternative when queries can be sorted
Key Topics to Cover
Binary search
Sorting
Sweep line
Counting
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
  • How would you answer queries for the count over a range [t1, t2) instead of a point?
  • What if streams are added while queries arrive?
  • How would you return which streams are live, not just how many?
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: streams as [start, end) pairs and queries as timestamps. Output: list of counts in query order. A stream is live at t when start <= t < end. n and q up to 10^5 each, so O((n + q) log n) i...

High-Level Design

A stream is live at t exactly when it has started (start <= t) and has not ended (end > t). Every stream that has ended by t has also started, so live(t) = #starts <= t - #ends <= t. Sort the star...


Submit Your Answer
Markdown supported