Ordered Message Receiver
MediumTrees ยท Uber
For each query [s, k], return the id of the k-th employee to receive a message that starts at employee s, or -1 if fewer than k employees receive it.
Employees are numbered 0 to n - 1; manager[i] is the manager of employee i, and the one top employee has manager[i] = -1. Employee s receives the message first. Each employee who receives it passes it to their direct reports in increasing id order, and a report's whole team receives it before the next report does.
Example 1
- Input:
- manager = [2, 2, -1, 1, 1, 3], queries = [[2, 5], [1, 4], [0, 2]]
- Output:
- [5, 4, -1]
- Explanation
- From employee 2 the message reaches 2, 0, 1, 3, 5, 4 in that order, so the 5th is 5. Employee 0 has no reports, so no 2nd receiver exists.
Example 2
- Input:
- manager = [-1], queries = [[0, 1], [0, 2]]
- Output:
- [0, -1]
Example 3
- Input:
- manager = [3, 0, 0, -1, 3], queries = [[3, 5], [0, 3], [4, 2]]
- Output:
- [4, 2, -1]
Constraints
- describes a single tree with exactly one
- and