Minimum number of elements to be removed to make XOR maximum | PHP implementation to find minimum number of elements to remove to get maximum XOR value ; First n in the below condition is for the case where n is 0 ; Function to find minimum number of elements to be removed . ; Driver code ; print minimum number of elements to be removed
< ? php function nextPowerOf2 ( $ n ) { $ count = 0 ; if ( $ n && ! ( $ n & ( $ n - 1 ) ) ) return $ n ; while ( $ n != 0 ) { $ n >>= 1 ; $ count += 1 ; } return 1 << $ count ; } function removeElement ( $ n ) { if ( $ n == 1 $ n == 2 ) return 0 ; $ a = nextPowerOf2 ( $ n ) ; if ( $ n == $ a $ n == $ a - 1 ) return 1 ; else if ( $ n == $ a - 2 ) return 0 ; else if ( $ n % 2 == 0 ) return 1 ; else return 2 ; } $ n = 5 ; echo removeElement ( $ n ) ; ? >