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

Tags: #<Tag:0x00007f242d93a1b8>


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
for i in range(n):
if(len(s) >= k):
del s[0]
return v


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 !