tracks is on repeat: after the last track the first one plays again, forever. tracks[i] is the length of the i-th track.
Pick a run of consecutive tracks from this endless stream whose lengths add up to exactly total. Return the fewest tracks such a run can have, or -1 if no run works.tracks=[4, 2, 5], total=9 → 2
The playlist loops: 4, 2, 5, 4, 2, 5, … The consecutive 5 and 4 add up to 9, which is two tracks.
tracks=[3, 1], total=10 → -1
The tracks alternate 3, 1, 3, 1, … A run of even length sums to a multiple of 4 and a run of odd length to an odd number, so 10 is out of reach.
tracks=[2, 2, 3], total=14 → 6
Two full loops add up to exactly 14, which is six tracks.
tracks=[4, 2, 5], total=9
2
Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.