Peak Concurrent Viewers for Each Facebook Live Stream

Last updated: November 29, 2026

Quick Overview

Given viewer sessions on Facebook Live as (stream_id, viewer_id, join_ts, leave_ts), return each stream's peak number of simultaneous viewers and the first time that peak was reached.

Meta
Data Manipulation (SQL/Python)
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given viewer sessions on Facebook Live as (stream_id, viewer_id, join_ts, leave_ts), return each stream's peak number of simultaneous viewers and the first time that peak was reached.

A Python question in Meta's technical screens for engineers and data engineers on Live and video infrastructure, where peak concurrency drives capacity and creator analytics. The interviewer checks the sweep-line idea, correct tie handling at equal timestamps, and per-stream grouping.

What the Interviewer Expects
  • Converts sessions to +1 and -1 events
  • Sorts events and sweeps while tracking the running count
  • Handles a leave and a join at the same timestamp deliberately
  • Groups by stream and records the time of the first peak
  • Explains O(n log n) cost and memory
Key Topics to Cover
sweep line
event sorting
concurrency
interval sessions
Facebook Live
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you compute this in SQL with a running sum?
  • How would you report concurrency per minute for a chart instead of just the peak?
  • What if leave events are missing because the app crashed?
  • How would you dedupe a viewer who joined from two tabs?
Sharpen Your Skills on Codemia

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

Practice SQL Problems
Sample Answer
Clarify the Data

Each row is one viewing session on a stream. A viewer is present on [join_ts, leave_ts), so someone leaving at 10 and someone joining at 10 do not overlap. Sessions with leave <= join are bad rows...

Approach

Turn every session into two points: (join, +1) and (leave, -1). Sort by time, and at equal times put -1 before +1 to respect the half-open intervals. Sweep, keep the running count, and update ...


Submit Your Answer
Markdown supported