Count Distinct Elements in Every Window of Size K in a Subarray
Given an array of size “n” and an integer “k” where k < n. Write a program to return the count of distinct elements in every subarray of size “k”.
For eg:
int arr[] = {1,2,3,4,1,3,4} , window size k = 4
For 1st window of size 4 (index 0-3) – subarray = {1,2,3,4}, distinct element = 4
For 2nd window of size 4 (index 1-4) – subarray = {2,3,4,1}, distinct element = 4
For 3rd window of size 4 (index 2-5) – subarray = {3,4,1,3}, distinct element = 3
For 4th window of size 4 (index 3-6) – subarray = {4,1,3,4}, distinct element = 3