Legiana, a Lyft user, is reviewing his rides from a specific day. However, the application is not retrieving the complete data for the rides, and they are not listed in the correct order. Can you help resolve this issue?
You are given a list of routes where each route is represented as a pair of cities [start, end]. Each route connects two cities directly. Your task is to reconstruct the entire route from the given segments so that the route is continuous and includes all the segments exactly once.
Input
A list of lists named routes, where each element is a list of two strings [start, end] representing a direct route from start to end.
Output
A single string representing the reconstructed route with cities joined by -> .
Example 1
Given: [[SFO, LA], [NYC, SFO], [OAK, NYC]]
Result: "OAK -> NYC -> SFO -> LA"
Example 2
Given: [[A, E], [M, B], [C, A], [B, C]]
Result: "M -> B -> C -> A -> E"
Example 3
Given: [["Taco Bell", "Shake Shack"], ["Starbucks", "Wingstop"], ["Wingstop", "Taco Bell"]]
Output: Starbucks -> Wingstop -> Taco Bell -> Shake Shack
Example 4
Given: [[NYC, NJ]]
Result: "NYC -> NJ"
This Lyft VO question asks you to rebuild a continuous route from directed city pairs. The key idea is to identify the starting city using in-degree and out-degree counts, then follow each segment exactly once until the full path is reconstructed. If the problem is extended to multiple disconnected routes, each chain should be rebuilt separately and then sorted by length and starting city.