Data Structures & AlgorithmsHard

For 2 3 5 6 4 1 3, let P_i be the product of A[0..i] modulo 7 and S_i the product of A[i+1..n−1] modulo 7. How many indices i with 0 ≤ i ≤ n−2 satisfy P_i = S_i?

  1. A. 3
  2. B. 0
  3. C. 4
  4. D. 2

Correct answer: A. 3

Prefix and suffix products are computed once each in a single pass, then compared residue by residue. Excluding the element from the prefix side, counting the complement, or including the element on both sides each change the count.

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

Exams that ask this topic