Back to problems

Fruit Into Baskets (Sliding Window variant)

Algorithm · Amazon · Medium

Problem: Largest Subarray Using at Most Two Different Values An integer array named fruits is provided, with fruits[i] representing the fruit variety growing on tree i. You may collect fruit from one continuous run of trees. You have exactly two baskets: A basket may contain fruit of just one variety. Neither basket has a capacity limit. Determine the greatest number of fruits you can collect, meaning the longest contiguous subarray that includes no more than two unique…

Checking your access…