PRINCE KUMAR’s Post

🔥 Day 172 of My LeetCode Journey Problem 129: Sum Root to Leaf Numbers 💡 Problem Insight: Today’s problem was about forming numbers from root-to-leaf paths in a binary tree and returning their total sum. Each path represents a number, so the challenge is building that number correctly while traversing. 🧠 Concept Highlight: The solution uses DFS with path accumulation: At each node, update the current value → current = current * 10 + node.val Traverse left and right When you reach a leaf, add the formed number to the total No need to store paths explicitly, just carry the value forward. 💪 Key Takeaway: Instead of storing full paths, carry forward the computed state. This keeps the solution clean, memory-efficient, and easy to reason about. ✨ Daily Reflection: This problem reinforced how tree traversal, combined with simple math, can solve seemingly complex problems. Understanding flow matters more than storing data. #Day172 #LeetCode #BinaryTree #DFS #PathSum #ProblemSolving #DSA #CodingJourney #Consistency

  • text

To view or add a comment, sign in

Explore content categories