Reported September 2026
StackAdaptmath

Maximum Bananas Delivered by a Camel

Reported by candidates from StackAdapt's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live StackAdapt OA. Under 2s to a working solution.
Founder's read

StackAdapt's September 2026 OA hands you a camel, a pile of bananas, and numbers up to 10^9. That last part is the whole point. You can't simulate this one unit by unit, because distance alone can hit a billion. It's the classic camel and bananas problem, but with real-valued caching and a six-decimal string answer. If you've never seen the closed-form trick, you'll burn an hour on DP that can't finish. If you blank, StealthCoder is the safety net running invisibly during the live assessment.

The problem

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 = 3000
distance = 1000
capacity = 1000
return = "533.333333"
Three-load and two-load shuttle phases precede the final one-way trip.
Example 2
bananas = 1000
distance = 100
capacity = 1000
return = "900.000000"
The entire load fits, so only the direct trip consumes bananas.

Constraints
1 <= bananas, capacity <= 10^9.
0 <= distance <= 10^9.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to think in phases by number of loads. With b bananas and capacity c, you need k = ceil(b/c) loads. Moving with k loads costs (2k-1) bananas per unit of distance, since you make k forward trips and k-1 returns. Once the stock drops to a multiple of c, one fewer load is needed, so you compute exactly how far you can travel at the current rate before the load count drops. Jump that whole segment in one step, then repeat. There are only about b/c phases, and each phase is O(1) math. The pitfall is stepping one unit at a time, which times out at 10^9. Also watch floats. Use doubles carefully, handle distance 0, handle the case where the stock runs out mid-phase and return 0, and format with exactly six decimals. StealthCoder is the hedge if the phase math slips away mid-OA.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Maximum Bananas Delivered by a Camel cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass StackAdapt's OA.

StackAdapt reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Bananas Delivered by a Camel FAQ

What's the trick in the StackAdapt camel bananas problem?+

Group the trip by how many loads you need, k = ceil(bananas/capacity). Each unit of distance costs 2k-1 bananas. Jump straight to the point where the load count drops instead of moving one unit at a time. Repeat until you reach the destination or run out.

Why does brute force fail here?+

Distance and bananas go up to 10^9, so a unit-by-unit simulation or a DP table over positions and stock is far too slow. You need phase jumps that run in O(1) per phase, with the number of phases bounded by bananas divided by capacity.

How do I handle the six decimal output?+

Compute with doubles, then format with exactly six digits after the decimal point, like a fixed-precision format call in your language. Example 2 must print 900.000000, not 900. Return 0.000000 when nothing arrives, so don't return an empty or negative value.

What edge cases should I test?+

Test distance 0, where all bananas arrive. Test capacity at least bananas, where the cost is just distance, as in Example 2. Test cases where the stock dies before the destination, and huge inputs like 10^9 for everything to confirm there's no loop per unit.

How do I prepare for this in 48 hours?+

Work through the two examples by hand until 533.333333 makes sense. Write the phase loop once, with the formula for how far you can go before the load count drops. Then test edge cases. Don't spend time on general DP, since this is math and greedy phase logic.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with StackAdapt.

OA at StackAdapt?
Invisible during screen share
Get it