FastPrepKill Process

Kill Process

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

pid[i] is a process ID and ppid[i] is its parent ID; parent ID 0 denotes a root.

Killing process kill also kills every descendant. Return all killed process IDs in ascending order.

Function

killProcess(pid: int[], ppid: int[], kill: int) → int[]

Examples

Example 1

pid = [1,3,10,5]ppid = [3,0,5,3]kill = 5return = [5,10]

Process 10 is a child of 5.

Example 2

pid = [1,2,3]ppid = [0,1,1]kill = 1return = [1,2,3]

Killing the root kills both children.

Constraints

  • pid.length == ppid.length.
  • Process IDs are unique and relationships form a forest.
  • kill appears in pid.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int[] killProcess(int[] pid, int[] ppid, int kill) {
  // Write your code here.
}
pid[1,3,10,5]
ppid[3,0,5,3]
kill5
expected[5,10]
Checking account…