Opening your workspace…
Workspace/Coding room
Opening your workspace…
A brewery schedules a quiet tasting shift across consecutive minutes. Each entry of noise is the nonnegative number of noisy machine-seconds during that minute. The shift may spend at most budget noisy seconds in total. Return the inclusive zero-based range [start, end] of the longest nonempty shift within budget. If several shifts have the same longest length, return the one starting earliest. If no minute can be included, return [-1, -1]. A shift cannot skip minutes.
[2,0,3,1,0,2], 4Output[1,4]Minutes 1 through 4 have total noise 4 and length 4. No length-5 shift fits.
[2,2,2], 4Output[0,1]Both length-2 shifts fit. The earlier one starts at minute 0.
Extend the right edge and keep a running sum. Because noise cannot be negative, removing minutes from the left can restore the budget without overlooking a longer valid shift.
Contrast a variable affordable window with an exactly fixed-width run.
Try this problem →Class SS · Arrays / Sliding window / QueuesMaintain a more complex validity rule while counting every valid window.
Try this problem →/** @param {number[]} noise * @param {number} budget * @returns {number[]} */ function solve(noise, budget) { // Return the longest affordable inclusive range. }
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.
[2,0,3,1,0,2], 4[1,4]