Rank Countries by Share of Video Watch Time Within Each Region

Last updated: November 29, 2026

Quick Overview

Given total Facebook Watch minutes by country with a region label, add each country's share of its region's minutes and its rank within the region, and return the top two countries per region.

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

0

0

0 solved


Given total Facebook Watch minutes by country with a region label, add each country's share of its region's minutes and its rank within the region, and return the top two countries per region.

Meta online assessments for data roles include short pandas tasks that test groupby transform, which is the pandas analog of a SQL window function. The interviewer or grader expects shares that sum to one per region and a rank method that matches the stated tie rule.

What the Interviewer Expects
  • Use groupby transform('sum') to broadcast the region total to each row
  • Compute share without collapsing rows
  • Rank within region with an explicit method for ties
  • Filter to top two per region after ranking
  • Pre-aggregate if a country appears more than once
Key Topics to Cover
groupby transform
share of total
rank
window functions
top-N
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
  • How would you show this as a percent of the global total at the same time?
  • Which rank method would you use if the business wants exactly two rows per region?
  • How would you write this in SQL with window functions?
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

Input watch(region, country, minutes). A country could appear more than once (for example separate rows per surface), so I first sum to one row per country. Ties in minutes share the same rank (`met...

Approach

Aggregate to one row per region and country. Then groupby('region')['minutes'].transform('sum') gives the region total aligned to each row, share is minutes divided by it, and `groupby('region')['mi...


Submit Your Answer
Markdown supported