A node is good if its value is at least the maximum value on the path from the root.
DFS while carrying maxSoFar. Count the node if node.val >= maxSoFar, then recurse with updated max.
The definition depends only on the path’s maximum, which can be maintained incrementally.
A node is good if its value is at least the maximum value on the path from the root.
DFS while carrying maxSoFar. Count the node if node.val >= maxSoFar, then recurse with updated max.
The definition depends only on the path’s maximum, which can be maintained incrementally.