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.
I did the whole thing top down with memoization. Even I was stuck with the infinite loop that was the wretched snake. To update the tail, I needed to go through the head, and the head eventually led to the tail, and so on.
To solve this, I just removed the entire snake from the array (hashmap in my case) after processing it's tail, and it worked.
"Also, since tail is updated only on getting lower value, no such tail will be updated more than once usually."
- No tail will EVER be update more than once?
Not sure if we're talking about the same thing.
Came here to see how other people solved this. Nice to see your answer.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Snakes and Ladders: The Quickest Way Up
You are viewing a single comment's thread. Return to all comments →
I did the whole thing top down with memoization. Even I was stuck with the infinite loop that was the wretched snake. To update the tail, I needed to go through the head, and the head eventually led to the tail, and so on. To solve this, I just removed the entire snake from the array (hashmap in my case) after processing it's tail, and it worked. "Also, since tail is updated only on getting lower value, no such tail will be updated more than once usually." - No tail will EVER be update more than once? Not sure if we're talking about the same thing. Came here to see how other people solved this. Nice to see your answer.