ESKO Coding Online Assessment Question
Anonymous User
377
Mar 30, 2020
Mar 30, 2020

You are assigned to develop a search algorithm that lists the available trains form city A to city B.
The algorithm must order the listing in price ascending order with the cheapest
train on top. if there are multiple trains for the same cost,the train with lesser
connections must be ordered higher. In case there are mutliple trains with the same cost and the same number of connections, then they are ordered alphabetically.

Input
The first line of the input contains the two cities for whom search is requested-
The departure city and the arrival city separated by white space.
The next N lines will contain the available trains and their cost.
Each line is a direct train starting with departure city name,arrival city name,cost

Output
The output is a list of M lines.Each line is one train listing.
Each of the M lines start with the departure city name,followed by a sequence of connecting city names(if exists), then followed by the arrival city name, and lastly followed by the total cost of that option.
When there are zero trains available,the output must contain a single line of text - No Trains

Example Input(1)
Bangalore Coimbatore
Bangalore Coimbatore 10000
Bangalore Chennai 4000
Chennai Coimbatore 5000
Chennai Coimbatore 6000

Example Output(1)
Bangalore Chennai Coimbatore 9000
Bangalore Coimbatore 10000
Bangalore Chennai Coimbatore 10000

Example Input(2)
Bangalore Coimbatore
Bangalore Coimbatore 10000
Bangalore Chennai 4000
Chennai Coimbatore 4000

Example Output(2)
Bangalore Chennai Coimbatore 8000
Bangalore Coimbatore 10000

Comments (2)