Question bank › Two Pointers
Dsa Two Pointers Easy

Balanced Fruits

You have a basket of fruits represented by an array of integers where each integer represents the type of fruit. Your task is to identify the maximum number of fruits you can collect consecutively without having more than two types of fruits in the basket. Print the maximum number of fruits you can collect. Input Format: - A single line containing integers separated by spaces (1 <= fruit_type <= 100). Output Format: - A single integer representing the maximum number of fruits. Example: Input: 1 2 1 2 3 Output: 4

Key concepts

two_pointersarrayssliding_window

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.