You are given a list of strings relationships. Each string has the form "employee:manager" and says that employee reports directly to manager. You are also given a name manager.
Return a sorted list of every employee who reports to that manager, directly or indirectly. An indirect report is an employee who reports to someone who, through one or more steps up the chain, reports to the given manager.
Function Signature
def get_reports(relationships: list[str], manager: str) -> list[str]:
Rules
-
Each string contains exactly one
:
. The part before it is the employee and the part after it is that employee's manager.
-
The given manager is not part of the result.
-
Each report appears once in the output, even if it can be reached through more than one relationship (for example, when the same line is listed twice).
-
Sort the result in ascending order by plain string comparison, which is the order Python's
sorted
gives.
-
If the given manager has no reports, return an empty list.
Constraints
-
1 <= len(relationships) <= 1000
-
Every relationship has the form
"employee:manager"
.
-
Employee and manager names contain alphabetic characters only.
-
The given
manager
appears somewhere in
relationships
.
-
There are no circular reporting chains.
Examples
Input: relationships = ["Bob:Alice", "Charlie:Bob", "Diana:Bob", "Eve:Alice", "Frank:Eve"], manager = "Alice"
Output: ["Bob", "Charlie", "Diana", "Eve", "Frank"]
Alice manages Bob and Eve directly, Bob manages Charlie and Diana, and Eve manages Frank. All five people sit under Alice, listed in sorted order.
Input: relationships = ["Bob:Alice", "Charlie:Bob", "Diana:Bob", "Eve:Alice", "Frank:Eve"], manager = "Bob"
Output: ["Charlie", "Diana"]
Bob manages Charlie and Diana directly, and neither of them manages anyone.
Input: relationships = ["Bob:Alice", "Charlie:Bob", "Diana:Bob", "Eve:Alice", "Frank:Eve"], manager = "Frank"
Output: []
Frank appears only as an employee, so nobody reports to him.