Loading…
Loading…
The plumber has taught the taps to sing. Any consecutive stretch can sing in chorus, but the smallest tap sets the volume. Tap i has capacity capacities[i], and a chorus sings at the lowest capacity among its members. The plumber auditions every stretch from minTaps through maxTaps taps long, inclusive. Return the exact sum of their volumes, with no modulus. Two stretches in different places get separate auditions, even if they sing the same note.
[4,2,3], 1, 2Output13The windows of length 1 have bottlenecks 4, 2 and 3, which add up to 9. Each of the two windows of length 2 has a bottleneck of 2, which brings the total to 13.
[5,5,5], 2, 3Output15There are two windows of length 2 and one of length 3, and each has a bottleneck of 5. It does not matter which of the equal taps you treat as the minimum.
Give each window to one position that holds its minimum, and break ties the same way every time so that no window is counted twice. Monotonic stacks tell you how far left and right a position stays the minimum. Then count the left and right extensions that keep the window length within the limits.
/** @param {number[]} capacities * @param {number} minTaps * @param {number} maxTaps * @returns {number} */ function solve(capacities, minTaps, maxTaps) { // Return the sum of the bottlenecks. }
Tab inserts two spaces. Shift+Tab outdents. Use the arrow keys and Tab to choose a suggestion. Press Escape, then Tab, to leave the editor. Press Control or Command with apostrophe to run samples or with Enter to submit.