n garden beds in a row, numbered 0 to n - 1; bed i needs needs[i] units of water. Two gardeners do the job: the left one, whose can holds left_can units, goes rightwards from bed 0, and the right one, whose can holds right_can, goes leftwards from bed n - 1. Both cans start full, both gardeners start at the same moment, and each bed takes them the same amount of time.
If a gardener's can holds enough water to fully water the next bed, they simply water it. Otherwise they instantly refill the can to the brim first and then water the bed.
If both gardeners reach the same bed, it is watered by the one whose can currently holds more water; on a tie, the left gardener does it.
Return the total number of refills.needs=[3, 4, 3, 5], left_can=6, right_can=7 → 2
The left gardener waters bed 0 (3 left), the right one waters bed 3 (2 left). The left one is short for bed 1 and refills; the right one is short for bed 2 and refills too. 2 refills in total.
needs=[2, 6, 2], left_can=6, right_can=6 → 1
After the outer beds both cans hold 4 units, a tie, so the left gardener takes the middle bed. 4 is less than 6, so one refill is needed.
needs=[7], left_can=7, right_can=9 → 0
needs=[3, 4, 3, 5], left_can=6, right_can=7
2
Run checks the first 3 tests in your browser. Submit checks all 67 tests on the server, hidden ones included.