The values of local variables inside functions that are called recursively are lost when the recursion unwinds. How can you save those values? This video explains.
I have written a book about recursion, “The Little Book Of Recursion”. You can find more about that here: http://bitwisebooks.com/books/little-book-of-recursion/
You can buy The Little Book Of Recursion from Amazon:
Amazon (US) https://amzn.to/2JjrJtq
Amazon (UK) https://amzn.to/2YCYx5N
Or search for its ISBN: 978-1913132057