text: Maximize sum of LSBs of Bitwise OR of all possible N / 2 pairs from given Array | Function top get LSB value of v ; Binary conversion ; Function to find the sum of LSBs of all possible pairs of the given array ; Stores the LSB of array elements ; Storing the LSB values ; Sort the array lab_arr [ ] ; Taking pairwise sum to get the maximum sum of LSB ; Print the result ; Driver Code ; Function Call
code: def chk ( v ) : NEW_LINE INDENT v = list ( bin ( v ) [ 2 : ] ) NEW_LINE v . reverse ( ) NEW_LINE if ( '1' in v ) : NEW_LINE INDENT v = v . index ( '1' ) NEW_LINE return ( 2 ** v ) NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT def sumOfLSB ( arr , N ) : NEW_LINE INDENT lsb_arr = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT lsb_arr . append ( chk ( arr [ i ] ) ) NEW_LINE DEDENT lsb_arr . sort ( reverse = True ) NEW_LINE ans = 0 NEW_LINE for i in range ( 0 , N - 1 , 2 ) : NEW_LINE INDENT ans += ( lsb_arr [ i + 1 ] ) NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT N = 5 NEW_LINE arr = [ 1 , 2 , 3 , 4 , 5 ] NEW_LINE sumOfLSB ( arr , N ) NEW_LINE