Hey techie 👀
We’re trying out a new thing here. We’ve got coding challenges that we want you to solve and become a better software engineer. And we care for you so much that we’ll even reward you for it. Solve the challenge below, submit it and win a $20 Amazon gift card!
We’ll be picking winners randomly from those who submit the right answer. And we’ll be announcing the winner on Friday with our next edition of AI Fridays - so hurry!
Coding Challenge: Flight Route Efficiency Calculator
You're tasked with developing a program that calculates the most efficient flight route based on fuel consumption. Given a list of flight routes between cities, along with the fuel consumption for each route, your program should find the route from a starting city to a destination city that consumes the least amount of fuel.
Input
A list of tuples representing flight routes between cities and their fuel consumption. Each tuple is in the format
(start_city, end_city, fuel_consumption)
, wherestart_city
andend_city
are strings, andfuel_consumption
is an integer representing the fuel consumption units for that route.A starting city
(start_city)
and a destination city (end_city
) for which the efficient route is to be calculated.
Requirements
Your program should input the list of routes, the starting city, and the destination city.
It should output the most fuel-efficient route between the starting and destination cities, including the total fuel consumption for that route.
If there are multiple routes with the same least fuel consumption, the program can return any one of them.
If there is no possible route between the given cities, the program should return an indication of that.
Example
Input:
Routes: [("New York", "London", 500), ("London", "Paris", 100), ("Paris", "Berlin", 50), ("New York", "Paris", 600), ("Berlin", "Tokyo", 250)]
Start City: "New York"
End City: "Tokyo"
Output:
Route: ["New York", "London", "Paris", "Berlin", "Tokyo"]
Total Fuel Consumption: 900
Feel free to ask for any clarifications or help as you tackle this challenge!
Why are we doing this again? I just passed the whole thing to ChatGPT, and understood the solution. And your $20 card will help me have a 1-month subscription to ChatGPT!