Giving an array and an int k;
find how mang subarrays which has at least k unique numbers(unique number means this number only appear once in this subarray)
for example:
[1, 2,1,1] k = 2
output : 2
[1, 2] and [2, 1]
[1, 2, 1] is unvalid because only have one unique number;
At first I tried two pointers left and right, when unique < right, keep right++; when unique == k then res += (len - right)
but soon I realized that is wrong because for example
[1, 2, 3, 4,1,2,5] k = 3
for left = 0, first I can find right = 2, but [1, 2, 3, 4] and [1, 2, 3,4,1] is valid and [1, 2, 3, 4,1, 2] is not, then [1, 2, 3,4,1,2,5] is valid again.
At last I gave a bruce force solution but couldn't able to solve the hidden cases.
Anyone please give an optimal solution?