22. Paths from root with a specified sum
Last updated
Was this helpful?
Last updated
Was this helpful?
The problem can be found at the following link:
I used a recursive approach to traverse the tree and find paths with the specified sum.
For each node, I added its value to the current sum and checked if it equals the target sum.
If a path with the sum is found, I added it to the result vector.
Time Complexity: The time complexity is O(N)
, where N is the number of nodes in the binary tree. This is because we visit each node exactly once.
Auxiliary Space Complexity: The space complexity is O(H)
, where H is the height of the tree. In the worst case, the space required for the call stack is the height of the tree.
For discussions, questions, or doubts related to this solution, please visit our . We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the repository.