Problem Solving with Go course

Sorting and SearchingQuiz: Sorting and Searching

Problem Solving with Go

Display

Theme

Sorting and Searching · Quiz

Quiz: Sorting and Searching

Check what you know about sorting with compare functions, binary search, two pointers, sliding windows and merging intervals. Answer every question below.

  1. Question 1 of 6This compare function is given to slices.SortFunc. In what order do the scores end up?
    func(a, b int) int {
    	return cmp.Compare(b, a)
    }
  2. Question 2 of 6xs := []int{3, 8, 8, 15, 20}. What does sort.Search(len(xs), func(i int) bool { return xs[i] >= 9 }) return?
  3. Question 3 of 6What must be true about f for sort.Search(n, f) to give the right answer?
  4. Question 4 of 6Merging two sorted slices of 1,000 values each with two pointers takes about how many steps?
  5. Question 5 of 6Why does the growing and shrinking sliding window need values that are never negative?
  6. Question 6 of 6The ranges 1-10 and 2-3 (both ends included) are merged after sorting. What is the right result?