Ad
  • Custom User Avatar

    I don't mind to be picking on other's people code but I think I found a small bug.

    If the processes are something like:
    [['1','a','c'],['2','a','b'],['3','b','c']]
    this solution will return ['2','3'] instead of ['1'] for start='a' and end='c'.

    This happens because the if is only checking the last element in the queue. If you change the order of the processes the correct solution emerges. The fix is simple, though, instead of just checking the last item, run a for loop over the whole queue.

    Something like this will work (to go right after the while line):
    for q in queue:
    if q[1] == end:
    return q[0]

    If there is something wrong with my reasoning, do let me know.
    I still think this solution is great, that's why I was trying to understand it and came across this issue :)