Getting TLE, Can anybody tell me why and how can i improve

amazon
Tags: #<Tag:0x00007f242d93a1b8>

#1

from collections import Counter
class Solution:
# @param A : list of integers
# @param B : integer
# @return a list of integers
def dNums(self, A, k):
v = []
n = len(A)
s = []
if (k > n):
return v
else:
for i in range(n):
s.append(A[i])
if(len(s) >= k):
v.append(len(Counter(s).keys()))
del s[0]
return v


#2

Try using a dictionary and a count variable. Figure out a way to improve your approach. Which elements will affect the count ? Every time you shift your window, the element being removed and the element being added can alter the count variable.
So find out a solution using these hints. All the best :slight_smile:
Happy Coding !