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
November 29, 20260
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample Answer
Requirements
- Input: list of
(join, leave)withjoin < leave, integer seconds. - Output:
(peak, time)wheretimeis 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 ...