1653. Minimum Deletions to Make String Balanced

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1653

class Solution:
    def minimumDeletions(self, s: str) -> int:
        lb, ra = 0, s.count('a')
        res = len(s)
        for c in s:
            ra -= c == 'a'
            res = min(res, lb + ra)
            lb += c == 'b'
        return res