Distinct elements in array

If you are given an array of n integers of k distinct elements. Then how do I compute the maximum subsequence which has exactly f distinct elements (f< k). (like of all the subsequence which has f distinct elements among them the maximum)
Example question: (in this problem f==k-1)

Put them in set till the size of set is less than k and update the size of subseq. If size of set is k then remove the element from start till its size become k-1 and then check size of subseq.

1 Like

You can see this CodeChef: Practical coding for everyone

1 Like