Grokking Data Structures & Algorithms for Coding Interviews
0% completed
Solution: Count Good Nodes in a Binary Tree
Problem Statement
A node of a binary tree is good when no node on the path from the root to it holds a larger value. Return the number of good nodes.
Examples
Example 1
- Input: root =
[3, 1, 4, 3, null, 1, 5] - Expected Output:
4
Example 2
- Input: root =
[3, 3, null, 4, 2] - Expected Output:
3
Example 3
- Input: root =
[1] - Expected Output:
1
What the path is worth
Read the definition again and notice how little of the path actually matters
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%