Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X. Return the number of good nodes in the binary tree.
Example 1
Input: root = [3,1,4,3,null,1,5]
Output: 4
Explanation: The root 3 is always good. Node 4 (path 3 → 4) and node 5 (path 3 → 4 → 5) are good. The lower 3 (path 3 → 1 → 3) is good because nothing on its path is larger. Both 1s have a 3 above them, so they are not good. That makes 4 good nodes.
Example 2
Input: root = [3,3,null,4,2]
Output: 3
Explanation: The root 3, its child 3 (path 3 → 3) and the node 4 (path 3 → 3 → 4) are good. Node 2 has a 3 above it, so it is not. That makes 3 good nodes.
Example 3
Input: root = [1]
Output: 1
Explanation: The root is always good, so the single node counts: 1.
A node is good exactly when its value is at least the maximum value seen on the path from the root. Carry that running maximum down the recursion.
Run checks all cases above. Submit evaluates all test cases.