Data Structures & AlgorithmsVery hardTCS NQT · Infosys

How many distinct values v in the array [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] occur exactly v times?

  1. A. 5
  2. B. 3
  3. C. 6
  4. D. 4

Correct answer: D. 4

Build a frequency map, then check for each value whether its count equals the value itself. All four values satisfy this, so the answer is the number of such values.

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

Exams that ask this topic