Netflix | Internship Online Assessment | No of subarrays with at least K distinct integers

Given an array of integers and an integer K, find the number of subarrays with at least K distinct integers.
Example 1:
array = [1, 2, 1, 1] and k = 2
output=2; {1,2} and {2,1} are only possibilities

Example 2:
array = [1, 2, 3, 4, 1] and k = 4
output=6; {1, 2, 3}, {1, 2, 3, 4}, {1,2,3,4,1}, {2,3,4}, {2,3,4,1} and {3,4,1} are the only possibilities. Note that {1,2,3,4,1} is valid because it still has 3 distinct integers.

Comments (5)