Data Structures & AlgorithmsVery hard
Which statement about the prefix product P_i and suffix product S_i modulo a prime p is correct when a zero element is present?
- A. If the array contains a zero, every product that includes it is zero mod p, so prefix or suffix products on one side collapse to zero.
- B. Zeros never affect modular products.
- C. Prefix products are always non-zero.
- D. Suffix products equal the total product divided by the prefix.
Correct answer: A. If the array contains a zero, every product that includes it is zero mod p, so prefix or suffix products on one side collapse to zero.
Any product containing a zero factor is zero, so the comparison of prefix and suffix products collapses for splits that include the zero. Division by prefix products is then impossible, which is why prefix and suffix arrays are used instead.
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
- Evaluate the integer expression 2(3+4) - 5/(1+1) with integer division (truncation toward zero). What is the result?
- What is the minimum number of brackets that must be removed from ')()())(()' to make it a balanced sequence?
- In a 3 by 3 grid with no walls, how many cells are exactly 2 moves (up, down, left or right) away from the top-left corner?
- How many index pairs i < j in [3, 4, 4, 5, 7, 6] have values that differ by exactly 1?
- What is the length of the longest contiguous subarray of [1, 2, 1, 2, 3] that contains at most two distinct values?
- How many adjacent position pairs in the string abbaabab are equal to ab or ba (overlapping adjacent pairs counted)?