gary@interview:~/interview/coding/904-fruit-into-b….md$
$ cat ./coding/904-fruit-into-baskets.md
[Coding]

904. Fruit Into Baskets

────────────────────────────────────────────────────────────

904. Fruit Into Baskets

class Solution:
    def totalFruit(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] += 1

            while len(memo) > 2:
                d = fruits[slow]
                slow += 1
                memo[d] -= 1
                if memo[d] == 0:
                    del memo[d]
            ans = max(fast - slow, ans)
        return ans

--tags#Sliding Window
$ ls ./coding/ | grep -v 904-fruit-into-baskets
265. Paint House II256. Paint House143. Reorder List1762. Buildings With an Ocean View
← cd ../codingcd ~