Given an integer N and the task is to find the size of the largest group in a range 1 to N, where two numbers belong to the same group if xor of its digits is same.
Input: N = 13
There are 10 groups in total, they are grouped according to the xor of its digits of numbers from 1 to 13:  [1, 10] [2, 13] [3, 12]      .
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 xor of its digits of numbers from 1 to 2:  .
Out of these, both groups have the largest size that is 1.
To solve the problem mentioned above we have to store the xor of digit of every element from 1 to N using hash map and increment its frequency if it repeats. Then find the maximum frequency within the hash map, which would be the largest size of the group. And finally, count all the groups who have the same frequency count as the largest group and return the count.
Below is the implementation of above the 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.
- Count of largest sized groups while grouping according to product of digits
- Maximize number of groups formed with size not smaller than its largest element
- Find the largest number that can be formed with the given digits
- Find the Largest Cube formed by Deleting minimum Digits from a number
- Find the Largest number with given number of digits and sum of digits
- Reverse an array in groups of given size
- Minimum difference between groups of size two
- Count all possible groups of size 2 or 3 that have sum as multiple of 3
- Maximum difference between groups of size two
- Reverse an array in groups of given size | Set 2 (Variations of Set 1 )
- Reverse an array in groups of given size | Set 3 (Single traversal)
- Largest product of a subarray of size k
- Size of the largest divisible subset in an Array
- Largest palindromic number by permuting digits
- Largest number not greater than N which can become prime after rearranging its digits
- Length of largest subsequence consisting of a pair of alternating digits
- Largest component size in a graph formed by connecting non-co-prime nodes
- Find smallest number with given number of digits and sum of digits
- Minimum digits to be removed to make either all digits or alternating digits same
- Find the largest possible k-multiple set
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.