FastPrepCount Numbers with Sum of Digits

Count Numbers with Sum of Digits

Cisco logoCisco● EasyINTERNOA

Problem statement

Given an integer X, write an algorithm to find the number of integers which are less than or equal to X and whose digits add up to Y.

Input

The first line of input consists of an integer - inputNum1, representing the given number X. The next line consists of an integer - inputNum2, representing the given number Y.

Output

Print the count of numbers whose digits add up to Y for the given number X.

Note

If no numbers are found whose digits add up to Y for the given number X, then print -1.

Function

countNumbersWithSumOfDigits(inputNum1: int, inputNum2: int) → int

Examples

Example 1

inputNum1 = 20inputNum2 = 5return = 2

Note - Explanation is an educated guess :) There are two numbers less than or equal to 20 whose digits add up to 5: 14 (1 + 4) and 5 (5). Therefore, the output is 2.

Constraints

  • 🥭🥭

More Cisco problems

See Cisco hiring insights
Saved
public int countNumbersWithSumOfDigits(int inputNum1, int inputNum2) {
  // write your code here
}
inputNum120
inputNum25
expected2
Checking account…