Count of numbers in Array ending with digits of number N | Array to keep the track of digits occurred Initially all are 0 ( false ) ; Function to initialize true if the digit is present ; Variable to store the last digit ; Loop to iterate through every digit of the number N ; Updating the array according to the presence of the digit in n at the array index ; Function to check if the numbers in the array end with the digits of the number N ; Variable to store the count ; Variable to store the last digit ; Checking the presence of the last digit in N ; Function to find the required count ; Driver code ; Preprocessing
let digit = new Uint8Array ( 10 ) ; function digitsPresent ( n ) { let lastDigit ; while ( n != 0 ) { lastDigit = n % 10 ; digit [ lastDigit ] = true ; n = Math . floor ( n / 10 ) ; } } function checkLastDigit ( num ) { let count = 0 ; let lastDigit ; lastDigit = num % 10 ; if ( digit [ lastDigit ] == true ) count ++ ; return count ; } function findCount ( N , K , arr ) { let count = 0 ; for ( let i = 0 ; i < K ; i ++ ) { count = checkLastDigit ( arr [ i ] ) == 1 ? count + 1 : count ; } document . write ( count + " " ) ; } let N = 1731 ; digitsPresent ( N ) ; let K = 5 ; let arr = [ 57 , 6786 , 1111 , 3 , 9812 ] ; findCount ( N , K , arr ) ;