Kodewick
Start learning →
Mini challenge←→0 / 70

Sticker swap

#064Mini challengeMapsSlices6 min

Your stickers are in mine (with repeats), and the ones your friend wants are in wants (no repeats). You can only give a sticker away if you have 2 or more of it. Write Swaps(mine, wants) to return the stickers you can give, in the order of wants; none gives an empty slice.

Examples
Swaps([]string{"cat", "dog", "cat", "owl", "owl"}, []string{"owl", "dog", "cat"})→['owl', 'cat']
Swaps([]string{"cat"}, []string{"cat"})→[]
The functionfunc Swaps(mine, wants []string) []string
main.go
package main

func Swaps(mine, wants []string) []string {
	count := map[string]int{}
	for _, s := range mine {
		// your code here: add 1 to this sticker's count
	}
	give := []string{}
	for _, w := range wants {
		// your code here: if you have 2 or more of w, add it to give
	}
	return give
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.