for idx, str := range A { charMap := make(map[rune]int, 0) for _, char := range str { num, ok := charMap[char] if ok { charMap[char] = num + 1 } else { charMap[char] = 1 } } arrayWithMap[idx] = charMap }
for _, char := range A[0] { exist := true for _, charMap := range arrayWithMap { num, ok := charMap[char] if ok && num > 0 { charMap[char] = num - 1 } else { delete(charMap, char) exist = false break } } if exist { resultArray = append(resultArray, string(char)) } } return resultArray }