Data Structures & AlgorithmsHard

What is the sum of the sums of all contiguous subarrays of [999999999, 888888888, 777777777], taken modulo 1000000007?

  1. A. 888888824
  2. B. 333333309
  3. C. 999999895
  4. D. 8888888880

Correct answer: A. 888888824

Element a[i] (0-based) appears in (i+1)(n−i) subarrays, so the total is Σ a[i]·(i+1)·(n−i). The zero-based formula a[i]·i·(n−i) misses the element itself, and skipping the modulus gives a different number entirely.

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

Exams that ask this topic