classSolution:# Same as 926. Flip String to Monotone IncreasingdefminimumDeletions(self,s:str) ->int: dp =0# the number of characters to be deleted to make subso far balanced count_b =0for c in s:if c =='a':# 1. Delete 'a'.# 2. Keep 'a' and delete the previous 'b's. dp =min(dp +1, count_b)else: count_b +=1return dp