Construct the smallest possible Array with given Sum and XOR | Function to find array ; Array not possible ; Array possible with exactly 1 or no element ; Checking array with two elements possible or not . ; Given sum and value of Bitwise XOR ; Function call
function findArray ( sum , xorr ) { if ( xorr > sum sum % 2 != xorr % 2 ) { System . out . println ( " " ) ; return ; } if ( sum == xorr ) { if ( sum == 0 ) document . write ( " " + " " ) ; else document . write ( " " + 1 ) ; document . write ( " " + sum ) ; return ; } var mid = ( sum - xorr ) / 2 ; if ( xorr == 1 && mid == 1 ) { document . write ( " " + 3 ) ; document . write ( " " + xorr + " " + mid + " " + mid ) ; } else { document . write ( " " + 2 ) ; document . write ( " " ) document . write ( " " + ( xorr + mid ) + " " + mid ) ; } } var sum = 4 , xorr = 2 ; findArray ( sum , xorr ) ;