Question bank › Two Pointers
Dsa Two Pointers Easy

Nutrient Balance

You are given a string of characters where each character represents a different nutrient. A balanced nutrient intake is defined as a substrings where the number of 'A's equals the number of 'B's. Write a program to find the length of the longest balanced nutrient substring. Input: - A string consisting of characters 'A' and 'B' (1 ≤ |s| ≤ 100000). Output: - An integer representing the length of the longest balanced substring. Example: Input: AABBAAB Output: 6

Key concepts

two_pointersstringssubarray

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.