Kth Employee Reached in an Ordered Hierarchy
Implement kth_recipients(boss, queries).
Employees are numbered 0 through n - 1. boss[0] == -1; for every other employee i, boss[i] is the direct manager of i, and the array forms one rooted tree.
When data is sent to start, that employee receives it first. They then pass it recursively through their organization in depth-first preorder, visiting each employee's direct reports in ascending employee-number order.
Each query is (start, k), where k is one-indexed. Return the employee who is the kth recipient within start's subtree, or -1 if the subtree has fewer than k employees.
Constraints
-
1 <= n <= 200,000
-
1 <= len(queries) <= 200,000
-
The hierarchy is a valid rooted tree.
-
Query starts are valid indices and
k >= 1
.
Example behavior
If employee 2 directly manages employees 4 and 7, and 4 manages 5, transmission from 2 visits 2, 4, 5, 7 before any later sibling subtree.
Candidate clarifications
Confirm whether the start employee counts as recipient one, whether traversal is depth-first, the sibling ordering, and out-of-range behavior.