Given a binary tree, find the maximum value v for which there exist different nodes a and b where v = |a.val - b.val| and a is an ancestor of b.
DFS: pass the current minimum and maximum values seen on the path from root to current node. At each leaf, the answer candidate is max - min.
- dfs(node, minVal, maxVal):
- If node==null: return maxVal - minVal.
- Update minVal = min(minVal, node.val), maxVal = max(maxVal, node.val).
- Return max(dfs(left, minVal, maxVal), dfs(right, minVal, maxVal)).
- Time Complexity: O(N)
- Space Complexity: O(H)