Quartux Coding Challenge

Shortest Path

Have the function ShortestPath( strArr ) take strArr which will be an array of strings which models a non-looping Graph. The structure of the array will be as follows: The first element in the array will be the number of nodes N (points) in the array as a string. The next N elements will be nodes that can be anything (A, B, C ... Brick Street, Main Street .. etc). Then after the Nth element, the rest of the elements in the array will be the connections between all of the nodes. They will look like this: (A-B, B-C .. Black Street-Main Street .. etc.). Although, there may exist no connection at all.

An example of strArr may be ["4","A","B","C","D","A-B","B-D","B-C","C-D"]. Your program should return the shortest path from the first Node to the last Node in the array separated by dashes. So in the example above the output should be A-B-D. Here is another example with strArr being ["7","A","B","C","D","E","F","G","A-B","A-E","B-C","B-D","C-D","D-F","E-D","F-G"]. The output should for this array should be A-E-D-F-G