Count Numbers with Sum of Digits
Updated
Problem statement
You are given two integers, inputNum1 (call it X) and inputNum2 (call it Y).
Count the positive integers less than or equal to X whose digits add up to Y. For example, the digits of 14 add up to 1 + 4 = 5.
Return that count. If no such integer exists, return -1.
Function
countNumbersWithSumOfDigits(inputNum1: int, inputNum2: int) → intExamples
Example 1
inputNum1 = 20inputNum2 = 5return = 2There are two numbers less than or equal to 20 whose digits add up to 5: 5 and 14 (1 + 4). Therefore, the output is 2.
Constraints
1 ≤ inputNum1 ≤ 10^91 ≤ inputNum2 ≤ 100
More Cisco interview questions
- Check if a String Is a PalindromePHONE SCREEN · Seen Nov 2026
- Find Unique ElementsPHONE SCREEN · Seen Nov 2026
- First Letter to Appear TwicePHONE SCREEN · Seen Nov 2026
- Middle of a Linked ListPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Reverse a StringPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
- K-Step Bit Flip with RetentionPHONE SCREEN · Seen Nov 2026
- Todo Task Manager OperationsONSITE INTERVIEW · Seen Oct 2026
- Find the Duplicate Number Without Modifying the ArrayONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Enough Muffins for the LineSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Climb Stairs with One or Two StepsIntuit · OAIntuit interview questions
- Find an Entry of Pascal’s TriangleMorgan Stanley · OAMorgan Stanley interview questions
- Count Lucky TicketsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
- Maximum Signal Walk in a Server TreeTower Research Capital · OA
- Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
- Jump Game with Prime-3 StepsUber · OAUber interview questions
- Profitable Currency Exchange CycleOptiver · OAOptiver interview questions
- Count Valid A-B-C Sequences Under a Modulo-Four RuleInfosys · OAInfosys interview questions
- Unique Paths Through a GridPeopleStrong · OAPeopleStrong interview questions