Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: What is the smallest positive integer n such that 1 + 2 + … + n is divisible by 10?

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

Correct answer: B. 4

The triangular number n(n+1)/2 must be a multiple of 10. Testing only n that are multiples of 10 misses the smallest one, which is found by direct search.

More Coding Interview Problems questions

Exams that ask this topic