FastPrepMaximum Bananas Delivered by a Camel
Problems/Maximum Bananas Delivered by a Camel

Maximum Bananas Delivered by a Camel

StackAdapt logoStackAdapt● HardFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report establishes the task identity and central capability. This practice contract supplies only the portable interface, deterministic boundary rules, and output serialization needed for consistent execution.

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

Examples

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.

More StackAdapt problems

  • Build a Tree from Preorder and Inorder TraversalsONSITE INTERVIEW · Seen Sep 2026
  • Reservoir Sampling with Recorded DrawsONSITE INTERVIEW · Seen Sep 2026
  • Running Medians and PercentilesPHONE SCREEN · Seen Aug 2026
All StackAdapt interview questionsSee StackAdapt hiring insights
Saved
class Solution {
    public String maxDeliveredBananas(int bananas, int distance, int capacity) {
      // write your code here
    }
}
Checking account…