Embercode
✕
SortingQuick quiz

Sort then search

7 questions. Covers Sort then search in Python.

Questions 1 to 5 of 7

  1. 1. What does this program print? ``python import bisect sorted_values = [1, 3, 5, 7] print(bisect.bisect_left(sorted_values, 4)) ``
  2. 2. What does the program print on its two lines? ``python import bisect def count_in_range(sorted_values, lo, hi): return bisect.bisect_right(sorted_values, hi) - bisect.bisect_left(sorted_values, lo) days = [1, 4, 4, 6, 9] print(count_in_range(days, 4, 6)) print(count_in_range(days, 7, 8)) ``
  3. 3. Sorting puts equal values side by side, so a duplicate check only has to compare each value with its ___ in the sorted list.

    Type your answer.

  4. 4. The function in the bisect module that returns the leftmost position where a value can go, without breaking the order, is bisect.___.

    Type your answer.

  5. 5. Why doesn't a two-pointer pair sum in Python need a cast to avoid overflow, the way a fixed-size int in Java does?

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.