Find the size of largest group where groups are according to the xor of digits | c ++ implementation to Find the size of largest group , where groups are according to the xor of its digits . ; Function to find out xor of digit ; calculate xor digitwise ; return xor ; Function to find the size of largest group ; hash map for counting frequency ; counting freq of each element ; find the maximum ; Driver code ; initialise N
#include <bits/stdc++.h> NEW_LINE using namespace std ; int digit_xor ( int x ) { int xorr = 0 ; while ( x ) { xorr ^= x % 10 ; x = x / 10 ; } return xorr ; } int find_count ( int n ) { map < int , int > mpp ; for ( int i = 1 ; i <= n ; i ++ ) { mpp [ digit_xor ( i ) ] += 1 ; } int maxm = 0 ; for ( auto x : mpp ) { if ( x . second > maxm ) maxm = x . second ; } return maxm ; } int main ( ) { int N = 13 ; cout << find_count ( N ) ; return 0 ; }