human
Can you provide a code to check if it is possible to construct an Array of size N having sum as S and XOR value as X and the other steps required given the following:
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"
Solution in Python:
assistant
#Here is code to check if it is possible to construct an Array of size N having sum as S and XOR value as X and the other steps required.
 def findIfPossible ( N , S , X ) :
	if ( S >= X and S % 2 == X % 2 ) :
		if ( N >= 3 ) :
			return " Yes "
		if ( N == 1 ) :
			if ( S == X ) :
				return " Yes "
			else :
				return " No "
		if ( N == 2 ) :
			C = ( S - X ) // 2
			A = C
			B = C
			A = A + X
			if ( ( ( A ^ B ) == X ) ) :
				return " Yes "
			else :
				return " No "
	else :
		return " No "
N = 3
S = 10
X = 4
print ( findIfPossible ( N , S , X ) )