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.

30:00

Count Good Nodes in Binary Tree
medium
Topics
Companies

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
Constraints:
  • The number of nodes is in the range [1,105][1, 10^5].

  • 104Node.val104-10^4 \leq \text{Node.val} \leq 10^4

Input
arr ={"root":[3,1,4,3,null,1,5]}

Check node 3

3

1

4

3

1

5

Variables
No variables to display
DepthFunction Call
Stack empty
0/29