Dsa
Sliding Window
Warm-up
Fruits in a Basket
You are given an array of integers where each integer represents a type of fruit. You can pick fruits of only two types. Find the maximum number of fruits you can collect in one basket.
Input format:
- The first line contains an integer n (1 <= n <= 10^5).
- The second line contains n space-separated integers, each representing the type of fruit (1 <= type <= 100).
Output format:
- Print a single integer, the maximum number of fruits that can be collected in one basket.
Example:
Input:
5
1 2 1 2 3
Output:
4
Key concepts
sliding_windowarraysgreedy
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