Medium · Dynamic Programming
Minimum Deletions to Make String Balanced
Given a string s made only of 'a' and 'b', return the minimum number of characters to delete so that no 'b' comes before an 'a' in what remains.
Examples
Example 1
s = "aababbab"Output: 2 deletions
Example 2
s = "bbaaaaabb"Output: 2 deletions
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.