Check if it is possible to construct an Array of size N having sum as S and XOR value as X | Function to find if any sequence is possible or not . ; Since , S is greater than equal to X , and either both are odd or even There always exists a sequence ; Only one case possible is S == X or NOT ; ; Considering the above conditions true , check if XOR of S ^ ( S - X ) is X or not ; Driver Code
function findIfPossible ( N , S , X ) { if ( S >= X && S % 2 == X % 2 ) { if ( N >= 3 ) { return " " ; } if ( N == 1 ) { if ( S == X ) { return " " ; } else { return " " ; } } if ( N == 2 ) { let C = ( S - X ) / 2 ; let A = C ; let B = C ; A = A + X ; if ( ( ( A ^ B ) == X ) ) { return " " ; } else { return " " ; } } } else { return " " ; } } let N = 3 , S = 10 , X = 4 ; document . write ( findIfPossible ( N , S , X ) ) ;