Find the count of M character words which have at least one character repeated | Function to return the factorial of a number ; Function to return the value of nPr ; Function to return the total number of M length words which have at least a single character repeated more than once ; Driver code
function fact ( n ) { if ( n <= 1 ) return 1 ; return n * fact ( n - 1 ) ; } function nPr ( n , r ) { return fact ( n ) / fact ( n - r ) ; } function countWords ( N , M ) { return Math . pow ( N , M ) - nPr ( N , M ) ; } var N = 10 ; var M = 5 ; document . write ( countWords ( N , M ) ) ;