values and an integer need. Within a segment of the array, a *match* is a pair of positions i < j inside it with values[i] == values[j]. For instance, [5, 5, 5] has three matches.
Count the contiguous non-empty segments of values that contain at least need matches.values=[2, 7, 2, 7], need=2 → 1
Only the whole array has two matching pairs: the 2s at 0 and 2, and the 7s at 1 and 3.
values=[4, 4, 4], need=1 → 3
[4, 4] qualifies twice (at two positions), and so does [4, 4, 4] with three pairs.
values=[1, 2, 3], need=1 → 0
values=[2, 7, 2, 7], need=2
1
Run checks the first 3 tests in your browser. Submit checks all 119 tests on the server, hidden ones included.