DEV Community

Discussion on: Daily Coding Puzzles - Nov 4th - Nov 9th

Collapse
 
thejessleigh profile image
jess unrein

Go

func Scramble(str1 string, str2 string) (result bool) {
    m := make(map[string]int)

    for _, item := range strings.Split(str1, "") {
        m[item] += 1
    }

    for _, item := range strings.Split(str2, "") {
        if val, ok := m[item]; !ok || val == 0 {
            return false
        } else {
            m[item] -= 1
        }
    }

    return true
}