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 thik it's better to update the next 6 cells also ahead of the end of ladders (only if it has higher value than start) with min of current and (1+start of ladder). This will elliminate the need of recalculation lot of in between squares if a snake is used to come down a long. It'll automatically take into consideration improvements made by the ladder discovered till that square. Then just consider the tail of the snake and get min of current or head of the snake, as we iterate the squares increasingly. each square is considered once only.
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 thik it's better to update the next 6 cells also ahead of the end of ladders (only if it has higher value than start) with min of current and (1+start of ladder). This will elliminate the need of recalculation lot of in between squares if a snake is used to come down a long. It'll automatically take into consideration improvements made by the ladder discovered till that square. Then just consider the tail of the snake and get min of current or head of the snake, as we iterate the squares increasingly. each square is considered once only.