Count Good Nodes in Binary Tree
Medium · Trees · about 15 minutes
Asked at Microsoft, Amazon, Google, Meta.
Call a node good when nothing on the way down from the root to it (the root and the node included) has a larger value than the node itself. Count the good nodes.