Captain of the Biggest Squad
Problem
You are given a DataFrame `roster` with columns `player_id`, `player_name`, `squad_id`, and `role`. `player_id` is unique. Each row is a player belonging to a squad, with a `role` such as 'Captain' or 'Member'. Every squad has exactly one captain.
Find the captain of the squad with the most players. If two or more squads tie for the largest size, return the captain of each of them. Return `captain_name` and `squad_id`, ordered by `squad_id`.
Input data
Example rows — the live problem includes the full dataset.
| player_id | player_name | squad_id | role |
|---|---|---|---|
| 1 | Ravi | 10 | Captain |
| 2 | Mei | 10 | Member |
| 3 | Tomas | 10 | Member |
| 4 | Aisha | 20 | Captain |
| 5 | Bode | 20 | Member |
Expected output
Your answer should return 1 row with the columns captain_name, squad_id.
Starter code (Pandas (Python))
import pandas as pd
def captain_of_the_biggest_squad(roster) -> pd.DataFrame:
# Your code here
return rosterSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock