Count of largest sized groups while grouping according to product of digits | C # 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
using System ; using System . Collections ; using System . Collections . Generic ; using System . Text ; 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 ) { Dictionary < int , int > mpp = new Dictionary < int , int > ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { int t = digit_prod ( i ) ; if ( mpp . ContainsKey ( t ) ) { mpp [ t ] ++ ; } else { mpp [ i ] = 1 ; } } int ans = 1 ; int maxm = 0 ; foreach ( KeyValuePair < int , int > x in mpp ) { if ( x . Value > maxm ) { maxm = x . Value ; ans = 1 ; } else if ( x . Value == maxm ) { ans ++ ; } } return ans ; } public static void Main ( string [ ] args ) { int N = 13 ; Console . Write ( find_count ( N ) ) ; } }