Question bank › Two Pointers
Dsa Two Pointers Easy

Balanced Water Bottles

You have an array of integers where each integer represents the capacity of a water bottle. Your goal is to check if you can fill the bottles with exactly the same amount of water. You can only fill them from the leftmost bottle to the rightmost bottle. If at any point the amount of water is balanced between the two pointers (left and right), return 'YES'. If the process completes and there is no valid configuration, return 'NO'. Input: - The first line contains an integer n (1 <= n <= 100) - the number of bottles. - The second line contains n integers a[i] (1 <= a[i] <= 1000) - the capacities of the bottles. Output: - Print 'YES' if the water can be balanced between the leftmost and rightmost bottles at some point, otherwise print 'NO'. Example: Input: 5 1 2 3 2 1 Output: YES The function should determine if there exists a configuration where the left and right pointers can balance the filled water.

Key concepts

two_pointersarraygreedy

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.