Gotcha! global variable with recursion

Be careful with argument order and return values

Han Qi
Towards Data Science
5 min readOct 31, 2020

--

Photo by Andrea Ferrario on Unsplash

I was working on this leetcode question https://leetcode.com/contest/weekly-contest-212/problems/path-with-minimum-effort/ using backtracking and spent some time debugging strange output. This article discusses some pitfalls when using recursion with global variables, how to handle them, and how to change the code…

--

--

Shares ideas that I can’t find online. You can support my writing by joining Medium through https://hanqi01.medium.com/membership (affiliate link)