Help with logic

prob: https://hack.codingblocks.com/app/contests/2022/535/problem 2

sol: https://ide.codingblocks.com/s/396890

I’m not able to figure out where to write the backtracking step

Hey @raghav007
Sorry for late repsonse ,was facing issues with internet
In this u actually have to maintain a visited array as well so that u don’t revisit the visited state

check this https://ide.codingblocks.com/s/393823 for reference


I have used the visited array but not getting the correct answer . Can you please tell what is wrong

Hey @raghav007

ohh okay so previously I was trying to store the result in the input array itself. But visited is enough for both marking as visited and output right?

yeah correct . . . . . . . . .