If total elements is less than total no. of flavors or total unique elements are less than total no. of flavors. -> Max subsequence without one element = total no. of elements
Max subsequence will always have atleast one less unique elements, i.e. sum less than than A.P of total number of flavors. We can use set to keep track of unique elements, but that would be O(kn) approach since for every new sequence we will have to clear the set. So i have used map and another variable to keep track of new sequence. Whenever a sequence ends we know the sum will have become equal to AP of k flavors. So to reset the map I have used seqno which is the another variable. And on every iteration I update the length of the longest subsequence if it less than the maxsum.
I have tried many test cases but not sure where I am going wrong. Any help will be appreciated. If my approach/code is not clear, let me know I’ll try to explain it better.