Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: A sorted list has values 3, 7, 7, 9, 12, 12, 12, 15. How many distinct values lie within the range [7, 12] inclusive?

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

Correct answer: C. 3

Count distinct values, not positions, in the inclusive range. The values 7, 9 and 12 qualify, which makes three distinct values.

More Coding Interview Problems questions

Exams that ask this topic