Day 10 of 100 Days LeetCode Challenge: Count Good Nodes in Binary Tree

✅ Day 10 of 100 Days LeetCode Challenge Problem: 🔹 #1448 – Count Good Nodes in Binary Tree 🔗 https://lnkd.in/gDfr48AK Concepts Used: 🔹 Binary Tree 🔹 Depth-First Search (DFS) 🔹 Recursion 🔹 Path-based State Tracking Approach Summary: 🔹 Used DFS to traverse the tree from root to leaves. 🔹 Maintained the maximum value (maxi) seen so far along the path. 🔹 A node is considered good if its value is greater than or equal to maxi. 🔹 Updated maxi at each step and accumulated the count recursively. Key Insight: 🔹 “Good nodes” depend on the path from the root, not the entire tree. 🔹 Passing state (maximum so far) through recursion avoids extra storage. 🔹 This leads to a clean and efficient solution with optimal traversal. #LeetCode #100DaysOfLeetCode #Day10 #DSA #Daily #Programming #ProblemSolving #Python #CodingJourney #TechCareers

  • text

To view or add a comment, sign in

Explore content categories