Count of largest sized groups while grouping according to product of digits | Function to find out product of digit ; calculate product ; return the product of digits ; Function to find the count ; hash map for counting frequency ; counting freq of each element ; find the maximum ; count the number of groups having size of equal to largest group . ; initialise N
function digit_prod ( x ) { let prod = 1 ; while ( x != 0 ) { prod = prod * ( x % 10 ) ; x = Math . floor ( x / 10 ) ; } return prod ; } function find_count ( n ) { let mpp = new Map ( ) ; for ( let i = 1 ; i <= n ; i ++ ) { let t = digit_prod ( i ) if ( mpp . has ( t ) ) { mpp . set ( t , mpp . get ( t ) + 1 ) } else { mpp . set ( t , 1 ) } } let ans = 1 ; let maxm = 0 ; for ( let x of mpp ) { if ( x [ 1 ] > maxm ) { maxm = x [ 1 ] ; ans = 1 ; } else if ( x [ 1 ] == maxm ) { ans ++ ; } } return ans ; } let N = 13 ; document . write ( find_count ( N ) ) ;