Перейти к содержимому

Path Sum in Binary Tree 🌳 | DFS & Recursion in C++ | DSA Series #56

ARKAPRAVA CHAKRABORTY

0:00 / 0:00

Path Sum in Binary Tree 🌳 | DFS & Recursion in C++ | DSA Series #56

2 просмотра · 2 недели назад
ARKAPRAVA CHAKRABORTY
5 подписчиков
2 просмотра · 2 недели назад
Welcome to Day 56 of my DSA Journey! Today I solved Path Sum in C++ using DFS and Recursion. The goal is to determine whether the binary tree contains a root-to-leaf path whose node values add up exactly to the given targetSum. 💡 Key idea: At every node, subtract its value from the remaining target and recursively check the left and right subtrees. 🔹 If the node is NULL → return false 🔹 Subtract the current node's value from targetSum 🔹 At a leaf, check whether the remaining sum equals the leaf's value 🔹 Recursively explore both subtrees ⏱️ Time Complexity: O(n) 💾 Space Complexity: O(h), where h is the height of the tree 📚 Learning Resource (ChaiCode DSA): https://dsa.chaicode.com/signup?ref=N... If you found this video helpful: 👍 Like the video 💬 Share your thoughts in the comments 🔔 Subscribe for more DSA videos as I continue learning in public. Day 56 ✅ Another Binary Tree problem solved! 🌳🚀 #DSA #CPP #CPlusPlus #BinaryTree #PathSum #DFS #Recursion #LeetCode #Chaicode #Algorithms #DataStructures #CodingInterview #Programming #LearningInPublic