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

Open every published interview problem, solution, scene, and memory room free, with no account.

More Dynamic Programming problems