Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You are given a set of cities that are laid out in a circle, connected by a circular road that runs clockwise. Each city has
You are given a set of cities that are laid out in a circle, connected by a circular road that runs
clockwise. Each city has a gas station that provides gallons of fuel, and the distances between these
cities are known. You have a car that can drive some number of miles per gallon of fuel, and your
goal is to pick a starting city such that you can fill up your car in that city using that city's gas
station You can then drive to the next city, refill up your car with that city's fuel, drive to the next
city, and so on and so forth until you return back to the starting city with or more gallons of fuel
left. This city is called a preferred starting city. In this problem, it is guaranteed that there will
always be exactly one valid starting City
The problem set involves series of arrays. The first array is the distance between neighboring cities.
Assume that city is distances i away from city Since the cities are connected via a
circular road, the last city is connected to the first city. In other words, the last distance in the
distances array is equal to the distance from the last city to the first city. The second array is an
array of gas available at each city, where gas is equal to the gas available at city The total
amount of gas available from all gas stations is enough to travel to all cities. Your gas tank always
starts out empty, and a positive integer value for the number of miles that your car can travel per
gallon of fuel miles per gallon, or MPG is also given.
Write a function that returns the index of the preferred starting city.
Sample Input:
istances
fuel
The preferred starting city for the sample above is city
Develop a complete and clear pseudocode
Mathematically analyze your pseudocode and prove the efficiency class, using either induction, limits or step counts. State the method used
Please write it in C
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started