- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

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

# Find the maximum distance covered using n bikes in Python

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

## Example

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))

## Input

3, 100

## Output

183.33333333333334

- 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
- Program to find maximum distance between a pair of values in Python
- Program to find maximum distance between empty and occupied seats in Python
- Program to find minimum distance to the target element using 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++
- Python – Remove Elements in K distance with N
- Find the minimum and maximum amount to buy all N candies in Python
- Program to find total area covered by two rectangles in Python
- Program to find lexicographically smallest lowercase string of length k and distance n in Python
- Program to find the kth factor of n using Python