uncommited problems

This commit is contained in:
2022-07-06 00:33:16 +01:00
parent e061a8602f
commit 0c78e204ef
10 changed files with 194 additions and 2 deletions

View File

@@ -0,0 +1,30 @@
package main
import "sort"
func minDeletions(s string) int {
freq := make([]int, 26) // only lower-case english letters
for _, chr := range s {
freq[chr-'a']++
}
sort.Ints(freq)
count, max := 0, len(s)
for idx := len(freq) - 1; idx >= 0 && freq[idx] != 0; idx-- {
f := freq[idx]
if f > max {
count += f - max
f = max
}
if f > 0 {
max = f - 1
} else {
max = 0
}
}
return count
}
func main() {
println(minDeletions("bbcebab"))
}