Given an integer N, the task is to find the number of groups having the largest size. Each number from 1 to N is grouped according to the product of its digits.
Input: N = 13
There are 9 groups in total, they are grouped according to the product of its digits
of numbers from 1 to 13: [1, 11] [2, 12] [3, 13]      .
Out of these, 3 groups have the largest size that is 2.
Input: N = 2
There are 2 groups in total, they are grouped according to the product of its digits
of numbers from 1 to 2:  .
Out of these, 2 groups have the largest size that is 1.
To solve the problem mentioned above we have to store the product of digit of every element from 1 to N using hash map and increment its frequency if it repeats. Then we have to find the maximum frequency within the hash map, which would be the largest size of the group. Finally, count all the groups who have the same frequency count as the largest group and return the count.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find the size of largest group where groups are according to the xor of digits
- Sort the numbers according to their product of digits
- Differences between number of increasing subarrays and decreasing subarrays in k sized windows
- Merge k sorted arrays | Set 2 (Different Sized Arrays)
- Maximum sum of even indexed elements obtained by right shift on an even sized subarray
- Find the Largest number with given number of digits and sum of digits
- Maximize number of groups formed with size not smaller than its largest element
- Minimum digits to be removed to make either all digits or alternating digits same
- Count numbers in range such that digits in it and it's product with q are unequal
- Count all possible groups of size 2 or 3 that have sum as multiple of 3
- Count of ungrouped characters after dividing a string into K groups of distinct characters
- Sort an array according to count of set bits
- Sort an array according to the increasing count of distinct Prime Factors
- Sort an array according to count of set bits | Set 2
- Count of elements which form a loop in an Array according to given constraints
- Java | Handling TLE While Using Arrays.sort() Function
- Rearrange an array in order - smallest, largest, 2nd smallest, 2nd largest, ..
- Largest product of a subarray of size k
- Largest triplet product in a stream
- Sum and product of k smallest and k largest prime numbers in the array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.