- Related Questions & Answers
- Find the distance covered to collect items at equal distances in Python
- Program to find minimum distance that needs to be covered to meet all person in Python
- Find maximum distance between any city and station in Python
- Campus Bikes II in Python
- Find maximum operations to reduce N to 1 in Python
- Find maximum distance between any city and station in C++
- Maximum points covered after removing an Interval in C++
- Find the minimum and maximum amount to buy all N candies in Python
- Program to find maximum value of k for which we can maintain safe distance in Python
- Find fibonacci series upto n using lambda in Python
- Find the maximum repeating number in O(n) time and O(1) extra space in Python
- Find four factors of N with maximum product and sum equal to N - Set-2 in Python
- Find a positive number M such that gcd(N^M,N&M) is maximum in Python
- Minkowski distance in Python
- Hamming Distance in Python

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose there are n bikes and each can cover 100 km when they are fully fueled. We have to find the maximum amount of distance we can go using these n bikes. Here we can assume that all bikes are similar and a bike consumes 1 litre of fuel to cover 1 km distance. So, if n bikes start from same point and run parallel, we can go only 100 km, in this case our target is to cover maximum distance, with minimum fuel. And minimum wastage of fuel means minimum number of bikes used. If the bikes run serially, then helps to cover more distance. So, we transfer some amount of fuel from last bike to another bike and don’t run the last bike after certain point. But now the problem is what distance the fuel transfer has to be performed such that the maximum distance is covered and fuel tank of rest of the bikes do not overflow.

So, if the input is like n = 3 and fuel = 100, then the output will be 183.33

To solve this, we will follow these steps −

covered_diatance := 0

while n > 0 is non-zero, do

covered_diatance := covered_diatance + (fuel / n)

n := n - 1

return covered_diatance

Let us see the following implementation to get better understanding −

def maximum_distance(n, fuel): covered_diatance = 0 while (n > 0): covered_diatance = covered_diatance + (fuel / n) n = n - 1 return covered_diatance n = 3 fuel = 100 print(maximum_distance(n, fuel))

3, 100

183.33333333333334

Advertisements