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
def findArray ( _sum , xorr ) : NEW_LINE INDENT if ( xorr > _sum or _sum % 2 != xorr % 2 ) : NEW_LINE INDENT print ( " No ▁ Array ▁ Possible " ) NEW_LINE return NEW_LINE DEDENT if ( _sum == xorr ) : NEW_LINE INDENT if ( _sum == 0 ) : NEW_LINE INDENT print ( " Array ▁ is ▁ empty " , " ▁ with ▁ size ▁ 0" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Array ▁ size ▁ is " , 1 ) NEW_LINE print ( " Array ▁ is " , _sum ) NEW_LINE DEDENT return NEW_LINE DEDENT mid = ( _sum - xorr ) // 2 NEW_LINE if ( xorr & mid == 1 ) : NEW_LINE INDENT print ( " Array ▁ size ▁ is " , 3 ) NEW_LINE print ( " Array ▁ is " , xorr , mid , mid ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Array ▁ size ▁ is " , 2 ) NEW_LINE print ( " Array ▁ is " , ( xorr + mid ) , mid ) NEW_LINE DEDENT DEDENT _sum = 4 NEW_LINE xorr = 2 NEW_LINE findArray ( _sum , xorr ) NEW_LINE