[Python 3] Explained Solution (video + code)
\nhttps://www.youtube.com/watch?v=mSzz_bZUVCQ\n\nclass Solution:\n    def rob(self, root: TreeNode) -> int:\n        @lru_cache(None)\n        \n        def hel
[](https://www.youtube.com/watch?v=mSzz_bZUVCQ)\nhttps://www.youtube.com/watch?v=mSzz_bZUVCQ\n```\nclass Solution:\n    def rob(self, root: TreeNode) -> int:\n        @lru_cache(None)\n        \n        def helper(node, parent_stolen):\n            if not node:\n                return 0\n            \n            if parent_stolen:\n                # we did steal from parent\n                # the only option is to not steal since we stole from the parent\n                return helper(node.left, False) + helper(node.right, False)\n\n            else:\n                # we did NOT steal parent\n                # Given a choice to choose b/w stealing or not stealing\n                # stealing at the current node\n                steal = node.val + helper(node.left, True) + helper(node.right, True)\n                \n                # NOT stealing current node\n                not_stealing = helper(node.left, False) + helper(node.right, False)\n                \n                return max(steal, not_stealing)\n        \n        return helper(root, False)\n```
['Recursion', 'Python', 'Python3']