Skip to content

Coin row

planning ahead

Level 2 of 3

Also called Coin-row problem and Most money with no two neighbours, by dynamic programming.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from coin row's own run on the numbers shown.

choose one

question 1

How many comparisons does the method make on the row 6, 2, 9, 4, 3?

the answer, and why

the answer is B

4 to fill, one for each coin from the 2nd. Then the walk takes coins 5, 3 and 1, jumping back two each time, 3 more.

if you chose another

  • That is filling alone; the walk back compares too.
  • That is one for each coin, but filling skips coin 1 and the walk skips coins 4 and 2.
  • That counts the walk visiting every coin, but each take skips the coin before it.

new numbers

question 2

Which row makes the method compare the most times?

the answer, and why

the answer is A

7 coins: 6 to fill, and the walk takes coins 7, 5, 3 and 1, 4 more, 10 in all. The cheapest row of 7 still costs more than the dearest of 6.

if you chose another

  • The dearest row of 6, 5 + 4, which is 9. One coin fewer outweighs a dearer walk.
  • 4 to fill, and the walk takes coins 5, 3 and 1, 7 in all.
  • 1 to fill, and the walk leaves coin 2 and takes coin 1, 3 in all.

new numbers