Find the size of largest group where groups are according to the xor of digits | Java 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
import java . util . * ; class GFG { static int digit_xor ( int x ) { int xorr = 0 ; while ( x > 0 ) { xorr ^= x % 10 ; x = x / 10 ; } return xorr ; } static int find_count ( int n ) { HashMap < Integer , Integer > mpp = new HashMap < Integer , Integer > ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { if ( mpp . containsKey ( digit_xor ( i ) ) ) mpp . put ( digit_xor ( i ) , mpp . get ( digit_xor ( i ) ) + 1 ) ; else mpp . put ( digit_xor ( i ) , 1 ) ; } int maxm = 0 ; for ( Map . Entry < Integer , Integer > x : mpp . entrySet ( ) ) { if ( x . getValue ( ) > maxm ) maxm = x . getValue ( ) ; } return maxm ; } public static void main ( String [ ] args ) { int N = 13 ; System . out . print ( find_count ( N ) ) ; } }