Unique Seconds Watched per Video After Rewinds and Rewatches
Last updated: November 29, 2026
Quick Overview
Facebook Watch logs playback segments as (user, video, start_position, end_position). Users rewind and replay, so segments overlap. Compute how many distinct seconds of each video each user actually covered.
Meta
November 29, 20260
0
0 solved
Facebook Watch logs playback segments as (user, video, start_position, end_position). Users rewind and replay, so segments overlap. Compute how many distinct seconds of each video each user actually covered.
A Python data problem in Meta onsite loops for engineers on video products, where completion and coverage metrics depend on deduplicating overlapping playback. The interviewer checks interval merging, grouping, and the difference between watch time and coverage.
What the Interviewer Expects
- Distinguishes total watch time from unique coverage
- Groups segments per user and video before merging
- Sorts by start and merges overlapping or touching intervals
- Drops zero-length or reversed segments
- Explains O(n log n) cost and how it maps to Spark
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you compute percent of the video covered given video length?
- How would you do this in SQL using gaps and islands?
- What changes if segments can be logged with seek events instead of ranges?
- How would you find the most rewatched second of a video across all users?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Each row is a playback range in video-position seconds, not wall-clock time. Rewatching 20 to 30 twice should count those 10 seconds once. Ranges are half-open [start, end), so [0,10) and `[10,40)...
Approach
Group by (user, video). Sort each group by start. Walk the list keeping a current merged interval; if the next start is at or before the current end, extend the end with max; otherwise add the curre...