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.

But it resulted in a wrong answer for the following input:

1571224294146586375800

You can notice I have a set of visited nodes, and that I will process each node of the graph only once. Also, I'm processing the nodes in the order they are being added to the queue.

When processing node 1, I will add to the queue nodes from 2 to 7 with one roll. When processing node 6, I will add node 12 in the queue with two rolls. But I can arrive in node 12 with only one roll, by falling on node 7 after the first roll and use the ladder.
Since node 12 was first added to the queue with 2 rolls, I will process it using two rolls, and will not process it again with 1 roll (I have a continue on the code).

For the input I provided, it will result in an answer of 18. And HackerRank is accepting the solution.

But I can arrive on node 100 with only 13 rolls. The following method is correct and generates the answer of 13.

## Snakes and Ladders: The Quickest Way Up

You are viewing a single comment's thread. Return to all comments →

I noticed HackerRank is passing on all cases for a code that is incorrect.

To solve this problem, I implemented the following code:

But it resulted in a wrong answer for the following input:

You can notice I have a set of visited nodes, and that I will process each node of the graph only once. Also, I'm processing the nodes in the order they are being added to the queue.

When processing node 1, I will add to the queue nodes from 2 to 7 with one roll. When processing node 6, I will add node 12 in the queue with two rolls. But I can arrive in node 12 with only one roll, by falling on node 7 after the first roll and use the ladder. Since node 12 was first added to the queue with 2 rolls, I will process it using two rolls, and will not process it again with 1 roll (I have a continue on the code).

For the input I provided, it will result in an answer of 18. And HackerRank is accepting the solution.

But I can arrive on node 100 with only 13 rolls. The following method is correct and generates the answer of 13.