Problem Solving with Go course

Maps and SetsQuiz: Maps and Sets

Problem Solving with Go

Display

Theme

Maps and Sets · Quiz

Quiz: Maps and Sets

Check what you know about counting, sets, finding pairs, cycles and grouping with maps. Answer every question below.

  1. Question 1 of 6What does this program print?
    counts := map[string]int{}
    for _, w := range []string{"ab", "cd", "ab"} {
    	counts[w]++
    }
    fmt.Println(counts["ab"], counts["zz"])
  2. Question 2 of 6A program prints a map's keys with for range, and sometimes the order changes. What's the right fix?
  3. Question 3 of 6Why is a set often written as map[T]struct{}?
  4. Question 4 of 6When looking for two numbers that add up to a target in one pass, why is the current number checked before it's stored in the map?
  5. Question 5 of 6A state first appears at step 4 and comes back at step 10. The state at step 1001 equals the state at which step between 4 and 9?
  6. Question 6 of 6What's in items after this code?
    items := []string{"rope", "hook", "rope", "hook"}
    slices.Sort(items)
    items = slices.Compact(items)