funcsubdomainVisits(cpdomains []string) []string { countMap := make(map[string]int) var count int var subStr string for _, domain := range cpdomains {
for i, c := range domain { if c == ' ' { count, _ = strconv.Atoi(domain[:i]) subStr = domain[i+1:] break } } countMap[subStr] += count for i, c := range subStr { if c == '.' { countMap[subStr[i+1:]] += count } } }
res := make([]string, 0)
for key, value := range countMap { res = append(res, strconv.Itoa(value) + " " + key) } return res }