diff --git a/go/minimum-deletions-to-make-string-balanced.go b/go/minimum-deletions-to-make-string-balanced.go new file mode 100644 index 0000000..4a1a4e3 --- /dev/null +++ b/go/minimum-deletions-to-make-string-balanced.go @@ -0,0 +1,17 @@ +package main + +func minimumDeletions(s string) int { + dp := make([]int, len(s)+1) + + bs := 0 + for i, c := range s { + if c == 'b' { + dp[i+1] = dp[i] + bs++ + } else { + dp[i+1] = min(dp[i]+1, bs) + } + } + + return dp[len(s)] +}