You are viewing a single comment's thread. Return to all comments →
Sorry, I have no access to my laptop to check it. What is result of my code on this input, and what is the answer/sequence you expect for fhis input?
This goes into an infinite loop. What happens is-for a series of 0 to 6 here, it exhausts first at the node 4, starts off again at 4, and then after exhauting at node 6, arrives at 0 again, and the cycle repeats. We can use a hashmap mayB to mark off the ones used as start node. Just thinking out aloud.
The problem did not specify what to ouput for an invald input, but we can output -1 or something.
I believe there is always a solution.
All test cases have a solution, i.e., there is no case where there's no solution. We have to make sure that our test case has a solution. The mentioned test case clearly has no solution.