Label game performance by margin
Company: Atlassian
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: Medium
Interview Round: Technical Screen
Given a games DataFrame (or R data.frame) with columns: team_id, opponent_team_id, team_score, opponent_team_score, write code to: (1) Define a function that maps margin = team_score - opponent_team_score to labels: 'Blowout Win' (margin >= 20), 'Close Win' (1–19), 'Tie' (0), 'Close Loss' (-1 to -19), 'Blowout Loss' (<= -20). (2) Apply it to create a new column performance_label for every row. Provide both: (a) a vectorized Python solution using pandas (no per-row Python loop), and (b) an idiomatic R solution using dplyr or base R. Validate with this tiny example: team_id,opponent_team_id,team_score,opponent_team_score -> (1,2,95,70) => Blowout Win; (1,3,82,85) => Close Loss; (2,1,93,93) => Tie.
Quick Answer: This question evaluates proficiency in data manipulation and transformation by mapping numeric score margins to categorical labels and implementing vectorized operations in pandas as well as idiomatic R data-frame workflows.