Embercode
✕
ArraysQuick quiz

Mixed array review

6 questions. Covers Boolean seen arrays.

Questions 1 to 5 of 6

  1. 1. The simple way adds up every window from scratch. What is the time complexity of the fixed-size sliding window, which keeps a running sum, for n values and any window size k?
  2. 2. A difference array holds n values plus one extra entry. How much work does one range update take, where it adds v to every value from index l to index r?
  3. 3. Predict the output of this program. Ignore the trailing space after the last value. ``cpp #include <iostream> #include <vector> using namespace std; int main() { vector<int> diff(7, 0); diff[1] += 3; diff[4] -= 3; diff[0] += 1; diff[2] -= 1; int run = 0; for (int i = 0; i < 6; i++) { run += diff[i]; cout << run << ' '; } cout << '\n'; } ``
  4. 4. Why does rotateRight call k %= n before it reverses anything?
  5. 5. In a jagged array, a loop over row r reads each value in that row. Which inner loop bound is safe?

5 question(s) left on this page.