This is the code I used. Passes the test cases but WA and TLE in hidden test cases

```
def longest_sub():
n, k = map(int, input().split())
flavours = list(map(int, input().split()))
for i in range(n-1):
for j in range(n-1, 0, -1):
c = len(set(flavours[i:j+1]))
if c < k:
return len(flavours[i:j+1])
for i in range(t):
print(longest_sub())
```