~/boss / chest-row

Prefix sums

The Gold Towers

Stack the gold once, then answer any stretch with one subtraction.

Loading the fight…

How to beat it

Walk the row once and keep a running total: tower k holds all the gold up to chest k, and tower 0 is the empty start. Gold from chest i to chest j is tower j minus tower i − 1. Subtract tower i instead and you lose chest i: that's the classic off-by-one.

Now the real boss

Interviews ask for the code. Watch it run, then write it yourself, tested in Python, C++ or Java.

On your phone? Writing code is easier on a laptop: open bossfight.dev/problems/basics-prefix-sums there. Sign in with your email to keep your progress on every device.

More bosses

esc