Easy Python Solution using dictionary

interview-questions
Tags: #<Tag:0x00007f24267892a8>

#1

Comment body goes here.`class Solution:
# @param A : list of integers
# @param B : integer
# @return a list of integers
def dNums(self, A, B):
mp=dict()
if B>len(A):
return []
q=[]
ans=[]
for i in range(B):
mp[A[i]]=mp.get(A[i],0)
mp[A[i]]+=1
q.append(A[i])
ans.append(len(mp))
mp[q[0]]-=1
if mp[q[0]]==0:
mp.pop(q[0])
#q.pop(0)
for i in range(B,len(A)):
q.append(A[i])
mp[A[i]]=mp.get(A[i],0)+1
ans.append(len(mp))
tmp=q[i-B+1]
mp[tmp]-=1
if mp[tmp]==0:
mp.pop(tmp)
return ans

`