Opening your workspace…
Workspace/Coding room
Opening your workspace…
A long tasting counter holds cups in a fixed order, with each cup labeled by its blend ID. A flight takes a nonempty contiguous section of the counter. A flight qualifies when it contains exactly kinds distinct blend IDs and between minCups and maxCups cups, inclusive. Repeated cups of a blend contribute to the length but count as only one distinct blend. Count all qualifying flights. Different start or end positions describe different flights, even if the blend sequences match. Return the count without rearranging the cups.
[1,2,1,3], 2, 2, 3OUTPUT4The qualifying inclusive index ranges are [0, 1], [1, 2], [2, 3], and [0, 2]. The other length-3 flight has three blends.
[7,7,7], 1, 2, 3OUTPUT3Both length-2 flights and the length-3 flight have exactly one distinct blend. Single cups are too short.
Count flights with at most kinds blends, then subtract those with at most kinds - 1. For a fixed right endpoint, intersect the valid starting positions with those allowed by the two length limits.
Tab inserts two spaces. Press Escape, then Tab, to leave the editor. Press Control or Command and Enter to submit.
[1,2,1,3], 2, 2, 34Public samples only. These checks do not award ranked points.