
Invert team assignments
mediumInvert team assignments
Capital One Python Interview Question
Capital One stores which team each analyst belongs to as a dictionary from analyst name to team. Managers want the reverse view: each team and the analysts on it.
Write a function invert(assignments) that returns a dictionary from each team to the list of its analysts, sorted alphabetically.
Asked of
- Data Analyst
- Data Engineer
- Data Scientist
- ML Engineer
- AI Engineer
Example 1
Input
assignments = {"Raj": "Fraud", "Mei": "Credit", "Ana": "Fraud"}Output
{"Fraud": ["Ana", "Raj"], "Credit": ["Mei"]}Example 2
Input
assignments = {}Output
{}Explanation
In the first example, Ana and Raj are both on the Fraud team, so Fraud maps to ["Ana", "Raj"]. Mei is the only analyst on the Credit team.
Submit also runs 2 hidden test cases that check edge cases.
Company
Capital One
Difficulty
medium
Topic
dictionaries
Language
Python
Your code
Loading Python in the background. You can start writing.