Tap here to switch tabs
Problem
Submissions

Problem: Count Good Nodes in Binary Tree

Count Good Nodes in Binary Tree asks you to count nodes whose value is at least as large as every value on the path from the root to that node.

Statement

Given the root of a binary tree, a node X is considered good if on the path from the root to X, there are no nodes with a value greater than X.

Return the total number of good nodes in the binary tree.

Constraints:

  • The number of nodes in the binary tree is in the range [1,105][1, 10^5].

  • −104≤-10^4 \leq Node.val ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Good Nodes in Binary Tree

Count Good Nodes in Binary Tree asks you to count nodes whose value is at least as large as every value on the path from the root to that node.

Statement

Given the root of a binary tree, a node X is considered good if on the path from the root to X, there are no nodes with a value greater than X.

Return the total number of good nodes in the binary tree.

Constraints:

  • The number of nodes in the binary tree is in the range [1,105][1, 10^5].

  • −104≤-10^4 \leq Node.val ≤104\leq 10^4