educative.io

Permute String: confusion with Java code and corrosponding visual representation

I have been going through this problem and I am not able to co relate the visual representation of algo and the code written in Java.
For the java code there is a swap operation happening before recursion starts, how does that help? And is it really the same as represented in visual representation?

1 Like

Hi Adarsh,

Thank you for reaching out. We are happy to hear from you!

In response to your question, the values of “current_index” and “i” before recursion start will be same so the swap function will not do anything in its first call. Hope this clarifies your confusion.

If you have any further queries, please do let us know!

Best Regards,
Team Educative