Dsa
Two Pointers
Medium
Fruit in Baskets
You have a row of fruit trees, where each type of fruit is represented by an integer. You can only pick two types of fruits at once. Determine the maximum number of fruits you can collect in a single continuous basket (subarray) where you can collect at most 2 different types of fruits.
Example:
Input:
1 2 1 2 3
Output:
4
Key concepts
two_pointerssliding_windowgreedy
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now