Bucket YouTube Videos by Length and Compare Completion Rates

Last updated: November 29, 2026

Quick Overview

Join views to video durations, bucket videos into length bands with pd.cut, and report per bucket the view count, completion rate (watched at least 95 percent) and average fraction watched, keeping empty buckets.

Google
Data Manipulation (SQL/Python)
Data Scientist
Google
November 29, 2026
Data Scientist
Online Assessment
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Join views to video durations, bucket videos into length bands with pd.cut, and report per bucket the view count, completion rate (watched at least 95 percent) and average fraction watched, keeping empty buckets.

An online assessment style pandas task tied to YouTube creator analytics, where completion rates are compared across video lengths. The interviewer checks binning boundaries, the many-to-one join, ratio clipping for replays and that empty bands still show up.

What the Interviewer Expects
  • Join views to videos with a validated many-to-one merge
  • Compute watch fraction and clip values above 1
  • Bucket with pd.cut using explicit edges and labels
  • Keep empty buckets with observed=False
  • Drop zero-duration videos before dividing
Key Topics to Cover
pd.cut
binning
merge validation
completion rate
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • Longer videos naturally complete less. How would you compare a creator to others fairly?
  • How would you compute the median fraction watched per bucket?
  • Should the bucket be defined by video length or by the viewer's watch time? Why?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

videos(video_id, duration_s) and views(view_id, video_id, watch_s). A view is complete if it covers at least 95 percent of the video. Bands: under 1 minute, 1 to 4, 4 to 10, 10 to 20, and 20 minut...

Approach

Merge views to videos with validate='many_to_one', which raises if a video id is duplicated in the dimension table (a silent fan-out otherwise). Compute watch_frac, clipped at 1 because replays or...


Submit Your Answer
Markdown supported