Count Numbers with Digit Sum

Problem Overview

  • Count how many integers less than or equal to X have digits that add up to Y.
  • Input: X (first line) and Y (second line); Output: the count, or -1 if none.
  • Number theory context: digit-sum constraint with an upper bound.
  • A common coding interview problem and interview question on numeric properties.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: