A company's new-hire buddy program tracks, for every employee, who onboarded them. Each employee has a unique numeric ID, a name, and a sponsorId, the ID of the employee who sponsored their onboarding, or 0 if they joined with no sponsor at all. Given the roster and one flagged sponsor ID K, print the name of every employee who was NOT personally sponsored by the employee with ID K, in the same order the roster was given.
Line 1: two space-separated integers n and K, the number of employees and the flagged sponsor ID. Each of the next n lines contains an employee record: an integer id, a name (a single token of letters and/or digits, 1 to 30 characters), and an integer sponsorId (0 if the employee has no sponsor).
Print the name of every employee whose sponsorId is not equal to K, one name per line, in the same order the employees appeared in the input. If no employee qualifies, print nothing.
Example 1
Input
6 2 1 Ravi 0 2 Nora 0 3 Kofi 2 4 Elena 0 5 Tomas 1 6 Sana 2
Expected
Ravi Nora Elena Tomas
Explanation
K is 2. Ravi (sponsorId 0), Nora (0), Elena (0), and Tomas (1) all have sponsorId != 2, so they are printed in that input order. Kofi (sponsorId 2) and Sana (sponsorId 2) were sponsored by employee 2, so they are excluded. Output: Ravi, Nora, Elena, Tomas, each on its own line.
Example 2
Input
3 5 1 Amara 0 2 Ben 1 3 Chidi 2
Expected
Amara Ben Chidi
Explanation
K is 5, and none of the three employees has sponsorId 5, so every employee qualifies and all three names are printed in their original order: Amara, Ben, Chidi.
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 →