Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
The solution works, but confused about the backtracking (`currentPath.pop();`)Af...

Ray

Jan 21, 2022

The solution works, but confused about the backtracking (currentPath.pop();)

After currentPath.pop(); is called, I don't understand how the recursive function (count_paths_recursive()) is called again.

The tree traversal has already happened above with the left & right child nodes. Popping the currentPath array (removing last value) wouldn't call count_paths_recursive() again...

2

0

Comments
Comments
T
Thilak G3 years ago

I have the same question

Design Gurus
Design Gurus3 years ago

The recursive call has already happened.

When exiting the function, remove the current node from the path (which we have added during this function) so that when we go back from where this function was called (which was a recursive call), we can move forward (i.e., bac...

On this page