t=int(input())
for _ in range(t):
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=set(a)
if(len(s)<k):
print(n)
else:
pre=[-1]*(k+1)
seg=[0]*(k+1)
for i in range(n):
seg[a[i]]=max(seg[a[i]],(i-pre[a[i]]-1))
pre[a[i]]=i
for j in range(1,k+1):
seg[j]=max(seg[j],(n-1-pre[j]))
print(max(seg))
In python
1
4 3
1 2 3 2
You are always considering the segment from the start.
1 Like
Hello Sir can you please check this solution for the same problem
1
4 2
1 2 1 1
1 Like
Thanks a lot
1 Like