Peak Concurrent Viewers in a TikTok LIVE Room

Last updated: November 29, 2026

Quick Overview

Given a list of (join_time, leave_time) pairs for viewers of one LIVE stream, return the maximum number of viewers present at the same time and the earliest time it occurs. A viewer who leaves at time t is not counted together with one who joins at time t.

TikTok
Coding & Algorithms
Software Engineer
TikTok
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a list of (join_time, leave_time) pairs for viewers of one LIVE stream, return the maximum number of viewers present at the same time and the earliest time it occurs. A viewer who leaves at time t is not counted together with one who joins at time t.

TikTok LIVE surfaces concurrency numbers to creators and uses them for gifting leaderboards and capacity planning, so sweep line questions appear in early technical screens. The interviewer checks whether you turn intervals into events and get the tie-break at equal timestamps right.

What the Interviewer Expects
  • Converts each interval into a +1 join event and a -1 leave event
  • Sorts events so leaves come before joins at the same timestamp, matching the stated rule
  • Tracks the running count and the time the maximum was first reached
  • Gives O(n log n) time and explains why
  • Mentions the heap alternative and when counting sort on timestamps helps
Key Topics to Cover
sweep line
events
sorting
intervals
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 produce the full concurrency curve for a chart instead of just the peak?
  • If events arrive in real time from many edge servers, how would you keep an approximately correct live count?
  • How would you compute the peak across thousands of LIVE rooms at once?
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 (join, leave) with join < leave, integer seconds.
  • Output: (peak, time) where time is the earliest moment the peak is reached.
  • Half-open intervals [join, leave): leaving ...
High-Level Design

Sweep line. Each viewer creates two events: (join, +1) and (leave, -1). Sort by time, and at equal time process -1 before +1. Sorting tuples (time, delta) does this automatically because -1 ...


Submit Your Answer
Markdown supported