Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: What is the smallest positive integer x such that 1 + 2 + … + x is at least 100?

  1. A. 13
  2. B. 14
  3. C. 10
  4. D. 105

Correct answer: B. 14

T(13) = 91 < 100 and T(14) = 105 ≥ 100, so x = 14. Returning the last x below the target gives 13, using √100 gives 10, and 105 is the triangular number itself, not x.

More Coding Interview Problems questions

Exams that ask this topic