Count N | Stores the dp - states ; Function to calculate the count of N - digit numbers that contains all digits from [ 0 - 9 ] atleast once ; If all digits are traversed ; Check if all digits are included in the mask ; If the state has already been computed ; If the current digit is 1 , any digit from [ 1 - 9 ] can be placed . If N == 1 , 0 can also be placed ; For other positions , any digit from [ 0 - 9 ] can be placed ; Return the answer ; Given Input ; Function Call
let dp = new Array ( 100 ) ; for ( let i = 0 ; i < 100 ; i ++ ) { dp [ i ] = new Array ( 1 << 10 ) . fill ( - 1 ) ; } function countOfNumbers ( digit , mask , N ) { if ( digit == N + 1 ) { if ( mask == ( 1 << 10 ) - 1 ) return 1 ; return 0 ; } let val = dp [ digit ] [ mask ] ; if ( val != - 1 ) return val ; val = 0 ; if ( digit == 1 ) { for ( let i = ( N == 1 ? 0 : 1 ) ; i <= 9 ; ++ i ) { val += countOfNumbers ( digit + 1 , mask | ( 1 << i ) , N ) ; } } else { for ( let i = 0 ; i <= 9 ; ++ i ) { val += countOfNumbers ( digit + 1 , mask | ( 1 << i ) , N ) ; } } return val ; } let N = 10 ; document . write ( countOfNumbers ( 1 , 0 , N ) ) ;