04 Try it yourself Interactive

Walk the index across the array

Press Next to move i one cell to the right. The amber cell is the one being read on this step; emerald marks what the accumulator has already taken in — in max mode that is the single cell best came from, so on a step where best changes the new home is still amber and only turns emerald on the next press. Switch tabs and the shape of the walk is the same, but the seed, the start index and the body all change together: best is seeded from a[0] and starts at i = 1, sum is seeded with 0 and starts at i = 0. The interesting step is the second-to-last one: i reaches n, the guard refuses, and a[n] is never read.

Find the maximum
best seeded with a[0] · i from 1
2–9 whole numbers (0–99), commas or spaces.
Press Next to begin. Each press moves one step.


      
Index i
Reading a[i]
Accumulator0
Blocked reads0
step 0 / 0