Data Structures & AlgorithmsHardTCS NQT Digital · Infosys

Problem: A lucky 4-digit ticket has the sum of its first two digits equal to the sum of its last two digits. Each ticket number runs from 0000 to 9999 (leading zeros allowed). How many tickets are lucky?

  1. A. 100
  2. B. 615
  3. C. 670
  4. D. 385

Correct answer: C. 670

If N(s) two-digit pairs (00-99) have digit sum s, the lucky count is Σ N(s)² = 670 over s = 0..18. Adding N(s) instead of squaring gives 100, forbidding a leading zero gives 615, and stopping at s = 9 gives Σ (s + 1)² = 385.

More Coding Interview Problems questions

Exams that ask this topic