# 904. Fruit Into Baskets https://leetcode.com/problems/fruit-into-baskets/ ###### Medium ##### Solution ```python= class Solution: def totalFruit(self, tree: List[int]) -> int: buckets = Counter() count = 0 start = 0 end = -1 for t in tree: end += 1 buckets[t] += 1 while len(buckets) > 2: buckets[tree[start]] -= 1 if buckets[tree[start]] == 0: del buckets[tree[start]] start += 1 count = max(count,end-start+1) return count ``` ##### Tips * Sliding Window