[Python] Recursion, with explanation 【Question seen in a 2016 interview】
Question analysis\nThe question is composed of two requirements:\n- To remove a node, the child need to notify its parent about the child\'s existance.\n- To de
### Question analysis\nThe question is composed of two requirements:\n- To remove a node, the child need to **notify** its parent about the child\'s existance.\n- To determine whether a node is a root node in the final forest, we need to know [1] whether the node is removed (which is trivial), and [2] whether its parent is removed (which requires the parent to **notify** the child)\n\nIt is very obvious that a tree problem is likely to be solved by recursion. The two components above are actually examining interviewees\' understanding to the two key points of **recursion**:\n- passing info downwards -- by arguments\n- passing info upwards -- by return value\n\n---\n\n### Fun fact\nI\'ve seen this question in 2016 at a real newgrad interview. It was asked by a very well-known company and was a publicly known question at that time. I highly doubt that the company will ask this question again nowadays.\n\n---\n\n### Code [Python]\n\n```\nclass Solution(object):\n    def delNodes(self, root, to_delete):\n        to_delete = set(to_delete)\n        res = []\n        def walk(root, parent_exist):\n            if root is None:\n                return None\n            if root.val in to_delete:\n                root.left = walk(root.left, parent_exist=False)\n                root.right = walk(root.right, parent_exist=False)\n                return None\n            else:\n                if not parent_exist:\n                    res.append(root)\n                root.left = walk(root.left, parent_exist=True)\n                root.right = walk(root.right, parent_exist=True)\n                return root\n        walk(root, parent_exist=False)\n        return res\n```\n
[]