4090. Minimum String Length After Balanced Removals
My accepted Python solution to LeetCode problem 4090, Minimum String Length After Balanced Removals, running in 4ms.
- Difficulty: Medium
- Python
- Runtime 4ms
- Memory 18.1MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 4ms, memory 18.1MB, accepted 2025-12-30.
class Solution:
def minLengthAfterRemovals(self, s: str) -> int:
# We can remove any balanced substring
# The minimum remaining is |count_a - count_b|
# because we can always pair up a's and b's to remove
count_a = s.count('a')
count_b = s.count('b')
return abs(count_a - count_b)