Link: https://leetcode.com/problems/kill-process/
Solution:
Topics: DFS, simulation
Intuition
This is pretty clearly a tree problem. We just have to traverse every node starting at the kill
node and put all those nodes in a list. The approach is clear but the tree must be simulated because the edges are in an non-standard form.
The relationships can be refactored into an adjacency list…then the traversal and collection of killed nodes becomes trivial.
Implementation
Mnemonic
Your are in an apple orchard feeling very ADJitated. In your agitation, you cut a branch off a tree and the branch dies. You count the withered sub-branches and leaves.
Visual