-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (50 loc) · 797 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"sort"
)
func main() {
fmt.Println(minimumPushes("aabbccddeeffgghhiiiiii"))
}
func minimumPushes(word string) int {
var arr [26]int
for i := 0; i < len(word); i++ {
arr[word[i]-'a']++
}
var store []info
for i, v := range arr {
if v == 0 {
continue
}
store = append(store, info{
char: byte(i) + 'a',
count: v,
})
}
sort.Slice(store, func(i, j int) bool {
return store[i].count > store[j].count
})
mp := make(map[byte]int)
ind := 2
click := 1
pos := 0
for pos != len(store) {
if ind == 10 {
ind = 2
click++
}
n := store[pos]
mp[n.char] = click
pos++
ind++
}
var result int
for _, v := range store {
result += (mp[v.char] * v.count)
}
return result
}
type info struct {
char byte
count int
}