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?
- A. 3
- B. 0
- C. 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many subsets of exactly three elements of 1 2 3 4 5 6 (chosen by position) have XOR equal to 0?
- How many index pairs i < j in 1 2 3 4 5 6 7 8 have A[i] XOR A[j] equal to a POWER OF TWO (1, 2, 4, 8, …)?
- How many NON-EMPTY subsets of {1, 2, ..., 10} have a sum divisible by 10?
- How many NON-EMPTY subsets of 2 3 5 7 11 13 have a product that is at most 60?
- Among all arrays of length 4 with values in {1, 2, 3, 4}, the absolute differences between ADJACENT elements (three of them) must all be…
- Among all permutations of 1, 2, 3, 4, 5 with NO fixed point (no position i holds the value i), which permutation is lexicographically…