Data Structures & AlgorithmsVery hard

A subarray's average is at least K exactly when which quantity is non-negative for that subarray?

  1. A. The sum of (a[i] − K) over the subarray.
  2. B. The sum of a[i] alone.
  3. C. The product of (a[i] − K).
  4. D. The maximum of a[i] minus K.

Correct answer: A. The sum of (a[i] − K) over the subarray.

Average ≥ K is equivalent to sum ≥ K × length, which is sum of (a[i] − K) ≥ 0. That transformation turns an average test into a prefix-sum test.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic