Data Structures & AlgorithmsVery hard

How many pairs of positions i < j in the array 12 21 3 30 111 24 42 have DIGIT SUMS that are equal?

  1. A. 22
  2. B. 0
  3. C. 10
  4. D. 11

Correct answer: D. 11

Map every value to its digit sum, then count equal-key pairs by group size: a group of g equal keys contributes C(g,2). Doubling the answer, counting equal raw values, or counting the unequal pairs measures something else.

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

Exams that ask this topic