Total Unique Watch Time From Overlapping Playback Segments
Last updated: November 29, 2026
Quick Overview
A video player logs playback segments as [start, end) second offsets, and segments can overlap when users rewatch or scrub back. Return the total number of distinct seconds of the video that were watched.
TikTok
November 29, 20260
0
0 solved
A video player logs playback segments as [start, end) second offsets, and segments can overlap when users rewatch or scrub back. Return the total number of distinct seconds of the video that were watched.
TikTok uses completion rate and unique watch time as core ranking signals, and rewatch loops make raw durations misleading. This online assessment style question checks that you can merge intervals cleanly and compute their union length.
What the Interviewer Expects
- Sorts segments by start time
- Merges overlapping or touching segments in a single pass
- Sums merged lengths rather than raw lengths
- Handles unsorted input and fully nested segments
- States O(n log n) complexity
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 also report the most rewatched second?
- What if segments stream in and you must keep the union up to date after each insert?
- How would you compute average unique watch percentage across millions of plays efficiently?
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
[start, end)integer pairs, unsorted, possibly overlapping or nested. - Output: total length of their union.
- Touching segments like
[0,5)and[5,8)simply add up; merging them...
High-Level Design
Summing raw lengths would double count rewatches, which inflates completion signals for looping videos. Instead I compute the union. Sort by start. Keep a current merged segment [cs, ce). For each n...