## Groupon Interview Question

SDE1s**Country:**India

If the shortest path algorithm is to be used as blackbox, I think aasshishh has the right solution.

But if we can modify the shortest path algorithm so that instead of tracking only the min path to any node, we track all paths length to a certain node, we can easily return all the shortest paths in order.

As suggested above, apply the given algo and get the shortest path between A,B.

Now, in place of removing all edges one by one, why not, remove the shortest edge, and get the new path. That should be /can be the second shortest. I mean major shortest path algo are greedy ones, so this should suffice.

In case where post this we aren't able to find a path itself, then remove the next shortest edge and so forth until we get the path.

Find the shortest path between any two nodes. Let them be A and B.

- aasshishh April 03, 2013Now to get second shortest path between the same nodes, remove any one edge that is involved in the shortest path between the same nodes and calculate the shortest path. Do the above process for each of the node involved in shortest path and keep track of the minimum second shortest path found.