i neighbours beds i - 1 and i + 1, and the last bed neighbours the first one. The array beds holds the yield of each bed.
Harvesting two neighbouring beds would dry out the soil between them, so that is not allowed. What is the largest total yield you can collect?beds=[4, 7, 3, 6] → 13
Harvesting beds 1 and 3 is best: 7 + 6 = 13. Beds 0 and 2 give only 7.
beds=[9, 2, 1, 8] → 10
Beds 0 and 3 are neighbours around the circle, so they cannot both be taken. The best option is 9 + 1 = 10.
beds=[5, 5, 5] → 5
Any two of three beds in a circle are neighbours, so only one can be harvested.
beds=[4, 7, 3, 6]
13
Run checks the first 3 tests in your browser. Submit checks all 125 tests on the server, hidden ones included.