Tap here to switch tabs
Problem
Submissions

Problem: Minimum String Length After Balanced Removals

Try to solve the Minimum String Length After Balanced Removals problem.

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

Try to solve the Minimum String Length After Balanced Removals problem.

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'.