Maximum sum of nodes in a binary tree such that no two are adjacent.
Asked in the DSA stage. Given as a second problem in the last 10 minutes.
Implement max_non_adjacent_sum(root), where root is the root of a binary tree whose nodes have integer val, left, and right fields. Return the maximum sum of selected node values. Selecting neither a node nor any of its descendants is allowed. Test cases represent trees in level-order arrays, using null for missing children.
def max_non_adjacent_sum(root):