Data Structures & AlgorithmsHard
How many index pairs i < j in 2 5 3 9 4 7 6 satisfy A[i] < A[j] AND (A[j] − A[i]) divides (j − i)?
- A. 15
- B. 6
- C. 7
- D. 8
Correct answer: C. 7
The divisibility is of the index gap by the value difference, which is a non-trivial pairing test. Reversing the divisibility, dropping the increasing condition, or shifting the count changes the answer.
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 length exactly 2 in 2 4 7 9 1 3 6 8 consist of two values with the SAME parity?
- How many index triples i < j < k in 1 2 2 3 4 6 8 satisfy A[i] · A[j] = A[k]?
- 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 <…