Challenge: Trace the Complete Path of a Journey

Test your knowledge on hash table traversal with this coding exercise.

Problem Statement #

You have to implement the string tracePath(unordered_map<string, string> map) function, which will take in an array of source-destination pairs and return the correct sequence of the whole journey from the first city to the last.

Input #

An unordered_map of type <string, string> containing string pairs of source-destination cities.

Output #

A string of source-destination pairs in the correct order.

Sample Input #

map = {
  "NewYork": "Chicago",
  "Boston": "Texas",
  "Missouri": "NewYork",
  "Texas": "Missouri"
}
key: value

Sample Output #

Boston->Texas, Texas->Missouri, Missouri->NewYork, NewYork->Chicago

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.