You are viewing a single comment's thread. Return to all comments →
from collections import deque def quickestWayUp(ladders, snakes): shortcuts={start:end for start, end in ladders+snakes} q=deque([(1,0)]) visited=set([1]) while q: position, count=q.popleft() if position==100: return count for i in range(1, 7): new_position=shortcuts.get(position+i,position+i) if new_position not in visited: visited.add(new_position) q.append((new_position, count+1)) return -1
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 →