The Ironspire Crafting Guild tracks every member's direct mentor. A member may have no mentor (a founding member) or exactly one direct mentor, and any member may in turn mentor any number of other members directly. The guild masters want to recognize master mentors: members who personally (directly, not through a chain of mentorship) mentor at least 5 apprentices.
Given the full roster, print the names of all master mentors.
n, the number of guild members.n lines contains id name mentorId, describing one member: a unique integer id, a name, and the id of that member's direct mentor, or -1 if the member has no mentor.Print the names of all master mentors (members who are the direct mentor of at least 5 other members), one per line, sorted alphabetically in ascending order. If no member qualifies, print nothing.
Example 1
Input
6 1 Alice -1 2 Bob 1 3 Cara 1 4 Dana 1 5 Eli 1 6 Finn 1
Expected
Alice
Explanation
Alice (id 1) is the direct mentor of Bob, Cara, Dana, Eli, and Finn -- 5 apprentices, meeting the threshold, so Alice is printed. No one else has any apprentices.
Example 2
Input
7 1 Gia -1 2 Hank -1 3 Ivy 2 4 Jai 2 5 Kim 2 6 Leo 2 7 Moe 1
Expected
(empty)Explanation
Hank (id 2) directly mentors Ivy, Jai, Kim, and Leo -- only 4 apprentices, below the threshold of 5, and Gia only mentors Moe (1 apprentice). Nobody qualifies, so the output is empty.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →