Ad
  • Default User Avatar

    Making the change suggested by nmknco will help but it is not sufficient. Here is a counter-example:

                    ['a2', '1', '0']]```
    
    Now imagine we want to find the shortest path from '0' to '2'. The solution will loop forever.
    Dijkstra's shortest path algorithm provides a solution. One has to avoid placing nodes on the queue that have previously been popped off the queue.
    
  • Custom User Avatar

    You could also use collections.deque and call the popleft() method.
    Anyway, good job writting this concise solution.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution