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 comment actually made more sense to me. Especially your last paragraph. I'm new to graph problems, I understand BFS and DFS, but I didn't know how to approach the whole die rolls. The key in the BFS is to enqueue its adjacent nodes based on the max die roll value which is 6 (Could be 12 if using two dice), but you need to watch out for snakes while doing it. Also for me I checked if there were 6 consecutive Nodes with a snake head and if I found that true I return -1, I did this before the BFS no need to do a BFS if there is no possible solution.
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 →
This comment actually made more sense to me. Especially your last paragraph. I'm new to graph problems, I understand BFS and DFS, but I didn't know how to approach the whole die rolls. The key in the BFS is to enqueue its adjacent nodes based on the max die roll value which is 6 (Could be 12 if using two dice), but you need to watch out for snakes while doing it. Also for me I checked if there were 6 consecutive Nodes with a snake head and if I found that true I return -1, I did this before the BFS no need to do a BFS if there is no possible solution.