We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Truck Tour
You are viewing a single comment's thread. Return to all comments →
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.