Data Structures & AlgorithmsHard
How many index triples i < j < k in 1 2 3 4 5 6 7 have A[i] + A[j] + A[k] divisible by 3?
- A. 13
- B. 11
- C. 7
- D. 25
Correct answer: A. 13
Enumerate the index triples and test the residue of their sum mod 3; the residue classes of 1, 2, 0 mix in a balanced way here. Using pairs, a different residue, or the product condition each answer another 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 index pairs i < j in 1 2 3 4 5 6 8 15 satisfy A[i]·A[j] ≡ 1 (mod 7)?
- How many contiguous subarrays of 4 7 1 10 5 8 have (maximum − minimum) divisible by 3? (A single element gives 0, which counts as…
- What is the length of the shortest contiguous subarray of 3 8 2 5 1 4 6 whose sum is divisible by 5?
- How many binary strings of length 6 contain NO three equal bits in a row (no run of length 3 or more)?
- What is the minimum number of elements you must DELETE from 7 4 9 2 5 8 so that the sum of the remaining elements is divisible by 6?…
- In "xaybzaxxbab", what is the length of the shortest contiguous substring that contains the letter 'a' followed later by the letter 'b'…