The Kill Process interview question simulates a process management system in an operating system. You are given two arrays: pid (process IDs) and ppid (parent process IDs). These arrays together represent a tree structure of processes. When you "kill" a specific process, all its children and their descendants must also be killed. Your goal is to return a list of all IDs that should be terminated.
Companies like Goldman Sachs and Microsoft use the Kill Process coding problem to test a candidate's ability to represent and traverse hierarchical data. It tests whether you can convert a pair of arrays into a more useful structure like an Adjacency List. It evaluations your mastery of Tree interview patterns and graph search algorithms.
This problem is solved using Graph Traversal (BFS or DFS).
ppid and the value is a list of its children pids. This effectively transforms the parent pointers into a directed tree.pid = [1, 3, 10, 5], ppid = [3, 0, 5, 3]. Kill process 5.
0: [3], 3: [1, 5], 5: [10].[5].[10]. Queue = [10].[5, 10].ppid array for children at every step (), which is too slow. The Hash Map is essential for time.Whenever you are given parent-child relationships in two arrays, your first step should almost always be to build an Adjacency List. This is a foundational Hash Table interview pattern for all tree and graph problems.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Employee Importance | Medium | Solve | |
| Operations on Tree | Medium | Solve | |
| Smallest Common Region | Medium | Solve | |
| Minimum Time to Collect All Apples in a Tree | Medium | Solve | |
| Clone N-ary Tree | Medium | Solve |