Tap here to switch tabs
Problem
Submissions

Problem: Kill Process

Try to solve the Kill Process problem.

Statement

You are given nn processes, where each process has a unique process ID (pid) and a parent process ID (ppid). You are provided with two integer arrays pid and ppid of length nn, where pid[i] is the ID of the ii-th process and ppid[i] is the ID of its parent process.

Each process has only one parent process, but may have multiple child processes. Only one process has a ppid of 00, which means it does not have a parent process.

When a process is terminated, all of its direct child processes and all of their descendants are also killed.

Given an integer kill representing the ID of the process you want to terminate, return a list containing the IDs of all processes that will be killed. You may return the answer in any order.

Constraints:

  • n == pid.length

  • n == ppid.length

  • 1≤n≤5×1041 \leq n \leq 5 \times 10^4

  • 1≤1 \leq pid[i] ≤5×104\leq 5 \times 10^4

  • 0≤0 \leq ppid[i] ≤5×104\leq 5 \times 10^4

  • Only one process has no parent.

  • All the values of pid are unique.

  • kill is guaranteed to be in pid.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Kill Process

Try to solve the Kill Process problem.

Statement

You are given nn processes, where each process has a unique process ID (pid) and a parent process ID (ppid). You are provided with two integer arrays pid and ppid of length nn, where pid[i] is the ID of the ii-th process and ppid[i] is the ID of its parent process.

Each process has only one parent process, but may have multiple child processes. Only one process has a ppid of 00, which means it does not have a parent process.

When a process is terminated, all of its direct child processes and all of their descendants are also killed.

Given an integer kill representing the ID of the process you want to terminate, return a list containing the IDs of all processes that will be killed. You may return the answer in any order.

Constraints:

  • n == pid.length

  • n == ppid.length

  • 1≤n≤5×1041 \leq n \leq 5 \times 10^4

  • 1≤1 \leq pid[i] ≤5×104\leq 5 \times 10^4

  • 0≤0 \leq ppid[i] ≤5×104\leq 5 \times 10^4

  • Only one process has no parent.

  • All the values of pid are unique.

  • kill is guaranteed to be in pid.