Python Solution - getting TLE


#1

Can someone tell me why this code would fail for larger test cases?

   if B>len(A):
	        return []
        l = {} 
        for i in range(len(A)):
            if len(A[i:i+B]) == B:
                l[i] =len(set(A[i:i+B]))
        return (list(l.values()))

#2

You are converting every possible window to a set, which is O(n^2). Instead, dynamically keep count of distinct by seeing which number is leaving the window and which number is added to the window every time u slide the window to the right.