Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

root =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

A node is good if its value is at least the maximum value on the path from the root.

Approach

DFS while carrying maxSoFar. Count the node if node.val >= maxSoFar, then recurse with updated max.

Why it works

The definition depends only on the path’s maximum, which can be maintained incrementally.

Code
Loading...
Complexity
Time: O(n)
Space: O(h)
Solution
Updated: 2026-02-23

Idea

A node is good if its value is at least the maximum value on the path from the root.

Approach

DFS while carrying maxSoFar. Count the node if node.val >= maxSoFar, then recurse with updated max.

Why it works

The definition depends only on the path’s maximum, which can be maintained incrementally.

Code
Loading...
Complexity
Time: O(n)
Space: O(h)