leetle

Daily challenge for 2025-09-29

272. Count Good Nodes in Binary Tree

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.

Input is given as level-order array where null represents no node.

Example:
Input: root = [3,1,4,3,null,1,5]
Output: 4

Good nodes: 3,4,3,5 (root 3, right child 4, left grandchild 3, right grandchild 5)

Run this challenge interactively in Python or JavaScript when the app loads.