Data Structures & AlgorithmsModerateTCS NQT · Infosys

How many unordered pairs of positions in [12, 21, 30, 4, 13, 9, 102] have elements with the same decimal digit sum?

  1. A. 8
  2. B. 6
  3. C. 4
  4. D. 7

Correct answer: D. 7

Compute each element's digit sum once, then count equal values with a frequency map: a value occurring c times gives c(c−1)/2 pairs. Comparing the numbers themselves finds equal values, which is a different condition.

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

Exams that ask this topic