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.
defquickestWayUp(ladders,snakes):# Write your code heretemp={}fora,binladders+snakes:temp[a]=bqueue=deque()queue.append((1,0))visited=set()visited.add(1)whilelen(queue)>0:current,roll_count=queue.popleft()ifcurrent==100:returnroll_countforiinrange(1,7):next_pos=current+inext_pos=temp.get(next_pos,next_pos)ifnext_posnotinvisited:queue.append((next_pos,roll_count+1))visited.add(next_pos)return-1
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 →