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
digit = [ 0 ] * 10 NEW_LINE def digitsPresent ( n ) : NEW_LINE INDENT lastDigit = 0 ; NEW_LINE while ( n != 0 ) : NEW_LINE INDENT lastDigit = n % 10 ; NEW_LINE digit [ int ( lastDigit ) ] = 1 ; NEW_LINE n /= 10 ; NEW_LINE DEDENT DEDENT def checkLastDigit ( num ) : NEW_LINE INDENT count = 0 ; NEW_LINE lastDigit = 0 ; NEW_LINE lastDigit = num % 10 ; NEW_LINE if ( digit [ int ( lastDigit ) ] == 1 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT return count ; NEW_LINE DEDENT def findCount ( N , K , arr ) : NEW_LINE INDENT count = 0 ; NEW_LINE for i in range ( K ) : NEW_LINE INDENT if checkLastDigit ( arr [ i ] ) == 1 : NEW_LINE INDENT count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT count NEW_LINE DEDENT DEDENT print ( count ) NEW_LINE DEDENT N = 1731 ; NEW_LINE digitsPresent ( N ) ; NEW_LINE K = 5 ; NEW_LINE arr = [ 57 , 6786 , 1111 , 3 , 9812 ] ; NEW_LINE findCount ( N , K , arr ) ; NEW_LINE