I tried this problem using sliding window approach. But I couldn't find where i am wrong. I got WA at test case 2 . Is this approach right?
for test in range(int(input())): n,m,k=[int(i) for i in input().split()] a=[int(i) for i in input().split()] b=[int(i) for i in input().split()] dic_b={} for i in b: if i not in dic_b: dic_b[i]=0 dic_b[i]+=1 i=0 ans=0 cur=0 dic_a={} for j in range(n): if a[j] not in dic_a: dic_a[a[j]]=0 dic_a[a[j]]+=1 if a[j] in dic_b: if dic_b[a[j]]>=dic_a[a[j]]: cur+=1 if (j-i+1)==m: if cur>=k: ans+=1 dic_a[a[i]]-=1 if dic_a[a[i]]==0: del dic_a[a[i]] if a[i] in dic_b: cur-=1 i+=1
print(ans)
Any suggestions would be helpful! Thank you