Dsa
Two Pointers
Easy
Balanced Fruit Basket
You are given an array of integers representing fruits in a basket. Each integer corresponds to a different type of fruit. A balanced basket is defined as a subarray where the number of distinct fruits is exactly equal to the number of fruits in that subarray. Write a program that finds the maximum length of a balanced basket subarray.
Input:
- A single line containing space-separated integers (1 ≤ |arr| ≤ 100000).
Output:
- An integer representing the maximum length of a balanced basket subarray.
Example:
Input:
1 2 1 3 2
Output:
4
Key concepts
two_pointersarrayscount
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