educative.io

Accessing pathSum as Reference

This question is related to the previous question “all paths for a sum” where we have to delete the last element of a current_path so that when it moves to the other path, the current_path variable doesn’t store the values from a previous path and that there is only one current_path variable that is holding the value since recursive call just creates a reference to the variable.

However, it looks like in this question, we are able to store different values for the variable pathSum when it traverses the left and right subtrees at the same time. I am a little confused about how variable values in the recursive function works. If someone could share some resources specifically on this topic, that would be great.