Calculate User Deviation from Team Average Messages
Company: Google
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates proficiency with pandas group-wise computations, broadcasting of group aggregates, and DataFrame manipulation without renaming columns.
Tables
usage_stats(user_id INTEGER, team_id INTEGER, messages_sent INTEGER, date DATE)
Hints
- Use a window function to compute the team average without collapsing rows.
- Compute AVG(messages_sent) OVER (PARTITION BY team_id) and subtract it from messages_sent for each row.