KatInterview

Identify All Projects with Maximum Team Size

Arrays & HashingAuto-graded · 23 test cases
MediumAuto-gradedArrays & Hashingarrayshashinggrouping

Last updated

Group assignment pairs by project, count members per project, and return every project tied for the largest team.

You are given a list of project assignments. Each assignment is a pair [project_id, employee_id] indicating that a particular employee is assigned to a particular project. The same (project_id, employee_id) pair will never appear more than once.

Your task is to identify all projects that have the largest number of assigned employees. If multiple projects are tied for the maximum team size, return all of them.

Input:

  • assignments: a list of pairs, where each pair is [project_id, employee_id] (both integers).

Output:

  • A list of project IDs (integers) that have the maximum number of employees, sorted in ascending order.
  • If the input is empty, return an empty list.

Constraints:

  • 0 ≤ len(assignments) ≤ 100,000
  • 1 ≤ project_id, employee_id ≤ 1,000,000
  • No duplicate (project_id, employee_id) pairs will appear in the input.
  • Project IDs may be non-contiguous and in any order.

Examples

Example 1

Input: projects_with_max_team_size([[101, 1], [101, 2], [202, 3]])

Output: [101]

Example 2

Input: projects_with_max_team_size([[8, 1], [8, 2], [3, 4], [3, 5]])

Output: [3, 8]

Example 3

Input: projects_with_max_team_size([])

Output: []

Hints

Hint 1

Count how many times each project_id appears in the assignment list—that gives you the team size for each project.

Hint 2

Find the maximum team size across all projects, then filter to keep only those projects that match that maximum.

Hint 3

Handle the empty input case explicitly: if there are no assignments, there is no maximum, so return an empty list.