Tap here to switch tabs
Problem
Submissions

Problem: Minimum String Length After Balanced Removals

Minimum String Length After Balanced Removals asks you to find the minimum possible length after repeatedly deleting contiguous substrings with equal numbers of a and b characters.

Statement

Given a string s consisting of characters 'a' and 'b'.

In one operation, you can select any contiguous substring of s that contains an equal number of 'a' and 'b' characters and delete it. The remaining left and right segments are then concatenated together.

Return the minimum possible length of s after performing any number of such operations.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s[i] is either 'a' or 'b'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum String Length After Balanced Removals

Minimum String Length After Balanced Removals asks you to find the minimum possible length after repeatedly deleting contiguous substrings with equal numbers of a and b characters.

Statement

Given a string s consisting of characters 'a' and 'b'.

In one operation, you can select any contiguous substring of s that contains an equal number of 'a' and 'b' characters and delete it. The remaining left and right segments are then concatenated together.

Return the minimum possible length of s after performing any number of such operations.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s[i] is either 'a' or 'b'.