Data Structures & AlgorithmsModerateGATE CS · TCS NQT
How many index pairs i < j in the array [12, 21, 3, 30, 111, 9, 18] have numbers with equal digit sums?
- A. 12
- B. 9
- C. 14
- D. 11
Correct answer: D. 11
Group values by digit sum using a hash map and add the pair counts for each group. Digit sums: 3, 3, 3, 3, 3, 9, 9.
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 the array [1, 2, 3, 4, 6, 7, 8, 9] have a[i] a[j] mod 5 = 1?
- How many contiguous subarrays of length 3 in the array [1, 2, 3, 1, 2, 3, 3] have all three elements distinct?
- How many contiguous subarrays of [1, 2, 3, 4, 5] have a bitwise XOR less than 4?
- How many integers x with 1 <= x <= 200 satisfy gcd(x, 180) = 1?
- What is the smallest x such that lcm(1, 2, ..., x) exceeds 1,000,000?
- How many integers x with 1 <= x <= 100 satisfy x^2 mod 24 = 1?