Bucket WhatsApp Message Lengths and Compute Share per Country

Last updated: November 29, 2026

Quick Overview

Given a sample of WhatsApp text messages with country and character length, assign each message to length buckets (1-10, 11-50, 51-200, 201+) and return, for each country, the percentage of messages in each bucket as a wide table whose rows sum to 100.

Meta
Data Manipulation (SQL/Python)
Data Scientist
Meta
November 29, 2026
Data Scientist
Phone Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given a sample of WhatsApp text messages with country and character length, assign each message to length buckets (1-10, 11-50, 51-200, 201+) and return, for each country, the percentage of messages in each bucket as a wide table whose rows sum to 100.

A short pandas exercise in a Meta data science phone screen, framed around understanding messaging behavior across markets. The interviewer checks pd.cut boundary semantics, normalizing within a group, and producing a table that a product partner can read at a glance.

What the Interviewer Expects
  • Use pd.cut with explicit bins and labels and state whether edges are inclusive
  • Handle the open-ended top bucket with infinity
  • Normalize counts within each country so rows sum to 100
  • Keep empty buckets as zero columns with a stable order
  • Exclude or explicitly label invalid lengths such as zero
Key Topics to Cover
pd.cut
crosstab
normalize
categorical ordering
messaging metrics
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 test whether the bucket distribution differs significantly between two countries?
  • Would quantile-based buckets (qcut) be better here, and what would they hide?
  • How would you weight by user so heavy senders do not dominate?
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

Columns: msg_id, country, length (integer characters). Lengths of 0 should not exist for text messages, so I treat them as invalid and drop them, mentioning it. Bucket 1-10 means lengths 1 throu...

Approach

Integer lengths make right-inclusive bins easy: edges [0, 10, 50, 200, inf] with right=True map 1-10, 11-50, 51-200, 201+. pd.crosstab(country, bucket, normalize='index') gives row shares direct...


Submit Your Answer
Markdown supported