An event site prints "lucky" on every ticket whose number has digits that add up to exactly target. Tickets are numbered from 1 to limit.
Write countLuckyTickets(limit, target) that returns how many ticket numbers from 1 to limit (inclusive) have a digit sum equal to target.
Input: limit = 25, target = 5 Output: 3
5, 14, and 23.
Input: limit = 100, target = 10 Output: 9
19, 28, 37, 46, 55, 64, 73, 82, and 91.
1 <= limit <= 10^151 <= target <= 150Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #561 Count Ticket Numbers by Digit Sum. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.