A node X is good if there are no nodes with a value greater than X on the path from root to X. The root is always good.
DFS approach — track the maximum value seen so far on the path:
max_so_far as you traverse downgood_nodes(root)
4
good_nodes(TreeNode(1))
1