Embercode
✕
ArraysQuick quiz

Mixed array review

6 questions. Covers Boolean seen lists in Python.

Questions 1 to 5 of 6

  1. 1. The rotation by reversal method from this module rotates a list of n values in place. What is its time cost and its extra memory?
  2. 2. The naive fixed-size window method adds up each window from scratch. For n values and a window of length k, roughly how many additions does it do in total?
  3. 3. In a counting list for lowercase letters, what does ord('c') - ord('a') give, and so which slot does the letter c use?
  4. 4. A seen list is made with seen = [False] * 5. What does seen[-1] = True do?
  5. 5. What does this code print? ``python def add_range(diff, left, right, value): diff[left] += value diff[right + 1] -= value def recover(diff, n): result = [0] * n running = 0 for i in range(n): running += diff[i] result[i] = running return result diff = [0] * 5 add_range(diff, 0, 2, 4) add_range(diff, 2, 3, 1) print(recover(diff, 4)) ``

5 question(s) left on this page.