classSolution:deftotalFruit(self,fruits: List[int]) ->int: fast =0 slow =0 ans =0 memo =defaultdict(int)while fast <len(fruits): fruit = fruits[fast] fast +=1 memo[fruit]+=1whilelen(memo)>2: d = fruits[slow] slow +=1 memo[d]-=1if memo[d]==0:del memo[d] ans =max(fast - slow, ans)return ans