Kill Process

Problem Id: 582 Difficulty: Medium Tag: Tree Tag: Queue


The relationship of all the process if a tree (not a binary tree). So we should first construct a tree stored in the adjancent list format and then do a BFS to get all childrens of the given node.


from collections import defaultdict

class Solution:
    def killProcess(self, pid: List[int], ppid: List[int], kill: int) -> List[int]:
        adj = defaultdict(list)
        for node, parent in zip(pid, ppid):

        children = []
        self._dfs(kill, adj, children)
        return children

    def _dfs(self, node, adj, children):
        for child in adj[node]:
            self._dfs(child, adj, children)