As reported: Goldman Sachs Analyst CoderPad round (60 minutes, Java, Bengaluru, 2025): given a source and a destination station, print all the stations on the shortest path; follow-up: every edge has unit weight.
A train map is given as connections, pairs of station names [a, b] joined by a direct line (trains run both ways). Return the stations along the shortest route (fewest connections travelled) from source to destination, including both ends. If source == destination, return [source]; if there is no route, return [].
Example 1
connections = [["King's Cross St Pancras","Angel"],["Angel","Old Street"],["Old Street","Moorgate"],
["Moorgate","Bank"],["King's Cross St Pancras","Russell Square"],["Russell Square","Holborn"],
["Holborn","Chancery Lane"],["Chancery Lane","St Paul's"],["St Paul's","Bank"],
["Holborn","Covent Garden"]]
source = "Russell Square", destination = "St Paul's"
-> ["Russell Square","Holborn","Chancery Lane","St Paul's"]
Example 2
same map, source = "Angel", destination = "Angel"
-> ["Angel"]
Constraints: up to 10^4 stations and connections; station names are non-empty strings; in every test the shortest route is unique.
Code runner format: one JSON value per line: connections, source, destination. Implement shortestRoute(connections, source, destination); the harness prints the list of station names.