Maximum Bananas Delivered by a Camel
Problem statement
A camel starts with bananas bananas and must transport as many as possible across distance units. It can carry at most capacity bananas at once and consumes one banana per distance unit traveled, including return trips. Bananas may be cached at any real-valued position.
Return the maximum amount that reaches the destination, formatted with exactly six decimal places.
Function
maxDeliveredBananas(bananas: int, distance: int, capacity: int) → StringExamples
Example 1
bananas = 3000distance = 1000capacity = 1000return = "533.333333"Three-load and two-load shuttle phases precede the final one-way trip.
Example 2
bananas = 1000distance = 100capacity = 1000return = "900.000000"The entire load fits, so only the direct trip consumes bananas.
Constraints
1 <= bananas, capacity <= 10^9.0 <= distance <= 10^9.