Data Structures & AlgorithmsHard
How many index triples i < j < k in 1 2 2 3 4 6 8 satisfy A[i] · A[j] = A[k]?
- A. 6
- B. 8
- C. 24
- D. 11
Correct answer: A. 6
Enumerate index triples in order and test the product of the first two against the third value. Replacing the product by a sum, using ≤, or counting pairs whose product appears anywhere answers a different question.
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 contiguous subarrays of 3 3 2 4 1 2 have a sum EXACTLY equal to (their length) × (their minimum)?
- Why does the OR of a subarray change at most about log(maximum value) times as its right end extends from a fixed start?
- Why is the OR of a subarray always at least the maximum element of that subarray?
- When counting triangles from sorted stick lengths with a two-pointer scan, why does fixing the largest side k and moving the pointers i <…
- Why is the inequality test for a non-degenerate triangle with sorted sides written as ai + aj > ak for the largest side ak?
- To count subarrays with sum divisible by m, why does the equal-residue method fail for a subarray count that depends on the MAXIMUM element?