Chain of Command

Asked at IMC Trading · Coding Questions · Difficulty: Medium

In an organizational structure represented as a tree with `n` members, each member is a node. The tree structure is given by an array `parent[]`, where `parent[i] = -1` means the root node, and others indicate their superior's index. A command is issued from a node and propagates to all subordinates in order of their indices. Given the starting node from which a command is issued and the `k`-th person to receive the command, return their index.

Loading the problem…