The Find the Team Size interview question is a SQL data retrieval task. You are given an Employee table where each row contains an employee ID and a team ID. Your goal is to return a list of all employee IDs along with the total size of the team they belong to. Every employee should be included in the output.
Amazon ask the Find the Team Size coding problem to evaluate a candidate's basic SQL skills, specifically their ability to use Window Functions or Subqueries. It tests if you can perform an aggregation (counting team members) without collapsing the original rows into groups. It’s a standard Database interview pattern for entry-level positions.
This problem can be solved using two patterns:
COUNT(employee_id) OVER(PARTITION BY team_id). This is the most efficient and readable way to attach an aggregate value to every row.GROUP BY team_id, then join this back to the original Employee table on the team_id column.Table: (Emp:1, Team:8), (Emp:2, Team:8), (Emp:3, Team:9)
(1, 2), (2, 2), (3, 1).GROUP BY team_id and selecting employee_id. This will either cause a syntax error (in strict SQL) or only return one employee per team.SELECT clause, which can be slower than a window function or a single join.Master the OVER (PARTITION BY ...) clause. It is the single most useful SQL feature for tasks that require "mixing" aggregate data with individual record details. Practice using it for SUM, AVG, and COUNT.