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?

  1. A. 12
  2. B. 9
  3. C. 14
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic