Count of largest sized groups while grouping according to product of digits | Java implementation to Count the groups having largest size while grouping is according to the product of its 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 . ; Driver Code ; Initialise N
import java . io . * ; import java . util . * ; class GFG { static int digit_prod ( int x ) { int prod = 1 ; while ( x != 0 ) { prod *= x % 10 ; x = x / 10 ; } return prod ; } static int find_count ( int n ) { Map < Integer , Integer > mpp = new HashMap < > ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { int t = digit_prod ( i ) ; mpp . put ( t , mpp . getOrDefault ( t , 0 ) + 1 ) ; } int ans = 1 ; int maxm = 0 ; for ( Integer x : mpp . values ( ) ) { if ( x > maxm ) { maxm = x ; ans = 1 ; } else if ( x == maxm ) { ans ++ ; } } return ans ; } public static void main ( String args [ ] ) { int N = 13 ; System . out . print ( find_count ( N ) ) ; } }