Find the size of largest group where groups are according to the xor of 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 ; initialise N
function digit_xor ( x ) { let xorr = 0 ; while ( x ) { xorr ^= x % 10 ; x = x / 10 ; } return xorr ; } function find_count ( n ) { let mpp = new Map ( ) ; for ( let i = 1 ; i <= n ; i ++ ) { let t = digit_xor ( i ) ; if ( mpp . has ( t ) ) { mpp . set ( t , mpp . get ( t ) + 1 ) } else { mpp . set ( t , 1 ) } } let maxm = 0 ; for ( let x of mpp ) { if ( x [ 1 ] > maxm ) maxm = x [ 1 ] ; } return maxm ; } let N = 13 ; document . write ( find_count ( N ) ) ;