submission link

I ‘m finding max by updating the max when find new max length , but it give wrong answer in this test case: 1 1 1 2 2 1 1 1 1 1

Plese tell me where i’ m wrong .

You have to find the largest subarray with no more than K-1 distinct elements, not the largest subarray without a K. For that you’ll have to use a map. Refer here -

Note that you’ll have to use K-1 for this since you need no more than K-1 distinct elements.

1 Like

The problem says that at least one of the k flavours is missing. So, I think using strickly K-1 is wrong. For every segment, you choose there should be less than k distinct flavours.

As per your submission you are comparing flavours no. Instead, you should be comparing no. of distinct flavours in a sub segment.

1 Like

thank you very much for your help