← Back to challenges

Number of Lucky Tickets

JavaScriptHardalgorithmslogicnumbersmath

Instructions

Create a function that counts how many n-digit numbers have the same sum of the first half and second half of the digits (“lucky” numbers). The number n is even. For example, for n = 6, the numbers "001010", "112220", "000000" are lucky.

Examples

luckyTicket(2) ➞ 10

luckyTicket(4) ➞ 670

luckyTicket(12) ➞ 39581170420

Notes

There are checks for n > 10, so watch out for code performance.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.