Greatest difference Left and Right subtree count Node
Find the node with the max difference in the total number o0f descendents in its left subtree and right subtree.
Solution: sinking check, backtracking against global var
Base Case: if node == null: return 0;
Recursive rule:
From Children: receive number of nodes below
For current node: Check current left right diff against global max. If greater, update global max, add self to solution node
To parents: pass left count + right count + 1
Time Complexity: O(2^N) 2 recursive calls per node
Space Complexity: O(Height) recursive call stack
Last updated
Was this helpful?