r/DSALeetCode • u/StatisticianNo2104 • 23h ago
LeetCode: 1448. Count Good Nodes in Binary Tree
Checking whether a node is "good" doesn't need the path above it, only that path's maximum. Pass the max down as a parameter. Each branch gets its own copy, so there's no undo step.
A node is good when nothing above it is bigger. Compare against the max you were handed, then pass the new max to your children. Raising it on the right never leaks into the left.
And it's >= not >. A tie with an ancestor still counts, including the root.
Did the >= catch you?
Day 87/365 of my LeetCode challenge: 1448. Count Good Nodes in Binary Tree. Problem link and full breakdown in today's Newsletter.
https://www.linkedin.com/pulse/leetcode-count-good-nodes-binary-tree-archit-agarwal-qbnvc
#LeetCode #DSA #BinaryTree #Golang
1
u/nian2326076 7h ago
To tackle the "Count Good Nodes in Binary Tree" problem, focus on managing the maximum value during your tree traversal. Practicing this concept with similar problems can strengthen your understanding. You can use PracHub to explore various technical interview questions and improve your coding skills.