Count of all possible numbers not exceeding M having suffix N | Function to count the no . of digits of N ; Function to count all possible numbers having Suffix as N ; Difference of the A . P ; Count of the number of terms ; Driver Code
function digitsOf ( num ) { return num . toString ( ) . length ; } function count ( a , tn ) { let diff = Math . floor ( Math . pow ( 10 , digitsOf ( a ) ) ) ; return Math . floor ( ( tn - a ) / diff ) + 1 ; } let n = 25 , m = 4500 ; document . write ( count ( n , m ) ) ;