Count of integers obtained by replacing ? in the given string that give remainder 5 when divided by 13 | javascript implementation of the approach ; Function to find the count of integers obtained by replacing ' ? ' in a given string such that formed integer gives remainder 5 when it is divided by 13 ; Initialise ; Place digit j at ? position ; Get the remainder ; Return the required answer ; Driver code
var MOD = parseInt ( 1e9 + 7 ) ; function modulo_13 ( s , n ) { var dp = Array ( n + 1 ) . fill ( ) . map ( ( ) => Array ( 13 ) . fill ( 0 ) ) ; dp [ 0 ] [ 0 ] = 1 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < 10 ; j ++ ) { var nxt = s . charAt ( i ) - ' ' ; if ( s . charAt ( i ) == ' ' ) nxt = j ; for ( k = 0 ; k < 13 ; k ++ ) { var rem = ( 10 * k + nxt ) % 13 ; dp [ i + 1 ] [ rem ] += dp [ i ] [ k ] ; dp [ i + 1 ] [ rem ] %= MOD ; } if ( s . charAt ( i ) != ' ' ) break ; } } return parseInt ( dp [ n ] [ 5 ] ) ; } var s = " " ; var n = s . length ; document . write ( modulo_13 ( s , n ) ) ;