Recursion Problem

I have 1 doubt. My below code is working fine keypad problem but in line 22 if I will initialize j = j + 1 before recursion call like firstly I will write it as j = j+1; then I will pass into the recursion call names(inp, out, i+1, j). It will give the wrong output why?

CODE: https://ide.codingblocks.com/s/588294

You still need j for line 21, if you change the value of j by j=j+1 then you need to change it back to j=j-1 after the recursion call, for the next iteration of the loop. this is called backtracking.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.