Here instead of recursion, I tried to do this question by applying while loop and used a vector (for storing previous visits). But test case 0 is giving wrong answer rest all cases passed. Can you please guide me where I am going wrong in this method ?