I'm trying to solve the following Leetcode problem: https://leetcode.com/problems/path-sum-ii/description/
This solution I came up with is working: https://pastebin.com/ma3DtU5b
However, I was not happy with passing vector currentPath by value in my dfs function because of it uses too much memory by creating a new vector for each dfs function call.
So I modified the dfs function to pass vector currentPath by reference and added a backtracking instruction at line 9 here: https://pastebin.com/Kvn8CfwB
However this solution is not working and doesn't pass Leetcode test cases.
I read the Editorial solution for this problem and it looks very similar to my non-working one, except that it passes a remainingSum instead of a currentSum to the dfs function calls.
Please help me understand the difference and what's wrong in my solution, I tried to understand by myself and with the help of a LLM but I couldn't.