PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Imc

Find k-th recipient in command propagation order

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of tree traversals, subtree indexing, and order-statistics on rooted trees, focusing on DFS-preorder propagation when children are visited in ascending id.

  • medium
  • Imc
  • Coding & Algorithms
  • Software Engineer

Find k-th recipient in command propagation order

Company: Imc

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

## Chain of Command (k-th Receiver in DFS-by-Child-Id Order) A company org chart forms a rooted tree with `n` people (nodes), labeled `1..n`. You are given an array `parent[1..n]` describing the tree: - `parent[i] = -1` means `i` is the root (top leader) - otherwise, `parent[i]` is the direct manager (parent) of person `i` - each node has zero or more direct reports (children) ### Command propagation rule When a person `u` issues a command, it is sent to **all subordinates** of `u` (all descendants of `u`), using this strict order: 1. Consider `u`’s direct children, sorted by increasing person id. 2. Send the command to the smallest-id child first. 3. Before sending to the next child, the command must be **fully propagated** throughout the current child’s entire subtree using the **same rule**. This defines a deterministic traversal order over the descendants of `u`: - It is equivalent to a DFS preorder over `u`’s subtree **excluding `u`**, where children are visited in ascending id. ### Task Given: - `parent[1..n]` - an issuer `u` - an integer `k` (1-indexed) Return the person id of the **k-th** subordinate who receives the command in the propagation order. If `u` has fewer than `k` descendants, return `-1`. ### Input/Output - Input: `parent[]`, `u`, `k` - Output: the person id of the k-th recipient, or `-1` ### Notes / Assumptions - The input forms a valid tree (exactly one root). - `k` is 1-indexed over recipients (descendants only; the issuer `u` is not counted). - Constraints may be large (e.g., `n` up to 2e5), so an approach better than simulating propagation step-by-step for each query is typically expected (if multiple queries are present, state how many).

Quick Answer: This question evaluates understanding of tree traversals, subtree indexing, and order-statistics on rooted trees, focusing on DFS-preorder propagation when children are visited in ascending id.

Related Interview Questions

  • Return all combinations that sum to target - Imc (easy)
  • Choose container set to minimize waste - Imc (hard)
Imc logo
Imc
Dec 15, 2025, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
6
0

Chain of Command (k-th Receiver in DFS-by-Child-Id Order)

A company org chart forms a rooted tree with n people (nodes), labeled 1..n.

You are given an array parent[1..n] describing the tree:

  • parent[i] = -1 means i is the root (top leader)
  • otherwise, parent[i] is the direct manager (parent) of person i
  • each node has zero or more direct reports (children)

Command propagation rule

When a person u issues a command, it is sent to all subordinates of u (all descendants of u), using this strict order:

  1. Consider u ’s direct children, sorted by increasing person id.
  2. Send the command to the smallest-id child first.
  3. Before sending to the next child, the command must be fully propagated throughout the current child’s entire subtree using the same rule .

This defines a deterministic traversal order over the descendants of u:

  • It is equivalent to a DFS preorder over u ’s subtree excluding u , where children are visited in ascending id.

Task

Given:

  • parent[1..n]
  • an issuer u
  • an integer k (1-indexed)

Return the person id of the k-th subordinate who receives the command in the propagation order.

If u has fewer than k descendants, return -1.

Input/Output

  • Input: parent[] , u , k
  • Output: the person id of the k-th recipient, or -1

Notes / Assumptions

  • The input forms a valid tree (exactly one root).
  • k is 1-indexed over recipients (descendants only; the issuer u is not counted).
  • Constraints may be large (e.g., n up to 2e5), so an approach better than simulating propagation step-by-step for each query is typically expected (if multiple queries are present, state how many).

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Imc•More Software Engineer•Imc Software Engineer•Imc Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.