-
Notifications
You must be signed in to change notification settings - Fork 481
/
1169.go
42 lines (40 loc) · 1.08 KB
/
1169.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
type tx struct {
time int
city string
idx int
}
func invalidTransactions(transactions []string) []string {
data := make(map[string][]tx)
delt := make(map[int]int)
for i, v := range transactions {
it := strings.Split(v, ",")
t, _ := strconv.Atoi(it[1])
amout, _ := strconv.Atoi(it[2])
if amout > 1000 {
delt[i] = 0
}
data[it[0]] = append(data[it[0]], tx{time: t, city: it[3], idx: i})
}
for v, _ := range data {
sort.Slice(data[v], func(i, j int) bool {
return data[v][i].time < data[v][j].time
})
q := make([]tx, 0)
for _, it := range data[v] {
for len(q) > 0 && q[0].time < it.time - 60 {
q = q[1:]
}
for _, ix := range q {
if it.city != ix.city {
delt[it.idx], delt[ix.idx] = 0, 0
}
}
q = append(q, it)
}
}
res := []string{}
for i, _ := range delt {
res = append(res, transactions[i])
}
return res
}