Data Structures & AlgorithmsHardCodeforces Div2 B · GATE CS
How many index pairs i < j satisfy (a[i] + a[j]) mod 7 = 0 for the array [3, 4, 7, 10, 11, 14, 21, 5, 9]?
- A. 9
- B. 7
- C. 11
- D. 8
Correct answer: D. 8
Bucket each value by its residue mod 7; a pair works when the residues are r and (7 - r) mod 7. Residue 0 pairs only with residue 0 (since 0 + 0 = 0 mod 7), and residues r and 7 - r pair with each other; count each class separately to avoid double counting.
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 satisfy a[i] XOR a[j] = 6 for the array [1, 4, 7, 2, 5, 3, 6]?
- How many contiguous subarrays of [3, -1, 2, -2, 4, -3, 1] have sum exactly 2?
- What is the length of the longest contiguous substring of the binary string 1100101101 that contains equal numbers of 0s and 1s?
- How many index pairs i < j make a[i] times a[j] a perfect square, for the array [2, 8, 18, 5, 12, 9, 50, 25, 32]?
- Keys 10, 22, 31, 4, 15, 28, 17, 88, 59 are inserted in this order into an open-addressing table of size 11 with h(k) = k mod 11 and linear…
- A table of size 11 uses double hashing with h1(k) = k mod 11 and h2(k) = 1 + (k mod 9), probe position (h1 + ih2) mod 11. Keys 5, 16, 27…