Loading…
Loading…
The tasting counter is full of cups, and the sampler tray slides under any consecutive stretch of them. The visiting tea society has brought a very particular tray order. It must hold between minCups and maxCups cups, inclusive, and exactly kinds distinct blends. Given the blend ID blends[i] of each cup, return the number of stretches that fit the order. Two cups of the same blend take up two spaces but contribute just one blend. Count different start or end positions separately.
[1,2,1,3], 2, 2, 3Output4Four flights qualify: cups 0 to 1, cups 1 to 2, cups 2 to 3 and cups 0 to 2. The other flight of length 3 has three blends.
[7,7,7], 1, 2, 3Output3The two flights of length 2 and the flight of length 3 each have one blend. Single cups are too short.
Count the flights with at most kinds blends, then subtract the flights with at most kinds - 1. For each right end, work out which starting positions satisfy the blend limit and which satisfy the two length limits, and count the positions that satisfy both.
/** @param {number[]} blends * @param {number} kinds * @param {number} minCups * @param {number} maxCups * @returns {number} */ function solve(blends, kinds, minCups, maxCups) { // Count flights satisfying both the blend and length rules. }
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.