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
def findIfPossible ( N , S , X ) : NEW_LINE INDENT if ( S >= X and S % 2 == X % 2 ) : NEW_LINE INDENT if ( N >= 3 ) : NEW_LINE INDENT return " Yes " NEW_LINE DEDENT if ( N == 1 ) : NEW_LINE INDENT if ( S == X ) : NEW_LINE INDENT return " Yes " NEW_LINE DEDENT else : NEW_LINE INDENT return " No " NEW_LINE DEDENT DEDENT if ( N == 2 ) : NEW_LINE INDENT C = ( S - X ) // 2 NEW_LINE A = C NEW_LINE B = C NEW_LINE A = A + X NEW_LINE if ( ( ( A ^ B ) == X ) ) : NEW_LINE INDENT return " Yes " NEW_LINE DEDENT else : NEW_LINE INDENT return " No " NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT return " No " NEW_LINE DEDENT DEDENT N = 3 NEW_LINE S = 10 NEW_LINE X = 4 NEW_LINE print ( findIfPossible ( N , S , X ) ) NEW_LINE