Look Up the Active Bitrate Profile at a Playback Timestamp
Last updated: November 29, 2026
Quick Overview
During playback, the player switches bitrate profiles and logs (timestamp, profile) events in increasing time order per session. Build a structure that records switches and answers: which profile was active at time t (the latest switch at or before t), or None before the first switch.
TikTok
November 29, 20260
0
0 solved
During playback, the player switches bitrate profiles and logs (timestamp, profile) events in increasing time order per session. Build a structure that records switches and answers: which profile was active at time t (the latest switch at or before t), or None before the first switch.
TikTok's video player adapts bitrate to network conditions, and debugging rebuffering requires reconstructing what was active at any moment. This technical screen checks binary search on a sorted timeline and how you handle out-of-order inserts.
What the Interviewer Expects
- Stores timestamps per session in sorted order
- Uses bisect_right to find the latest switch at or before t
- Handles queries before the first switch
- Keeps appends O(1) when events arrive in order and explains the out-of-order fallback
- States O(log n) query time
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
- Events may arrive slightly out of order from the client; how do you keep queries correct?
- How would you compute total time spent on each profile over a session?
- How would you store this for millions of sessions and answer queries server-side?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
record(session, ts, profile), timestamps usually nondecreasing per session.active(session, t)returns the profile of the latest switch withts <= t, or None.- Many queries per session, so ...
High-Level Design
Per session keep two parallel lists: times and profiles. If the new timestamp is at least the last one, append in O(1). Otherwise insert with bisect.insort-style logic (O(n) shift, acceptable fo...