Construct an Array of size N in which sum of odd elements is equal to sum of even elements | Function to construct the required array ; To construct first half , distinct even numbers ; To construct second half , distinct odd numbers ; Calculate the last number of second half so as to make both the halves equal ; Function to construct the required array ; check if size is multiple of 4 then array exist ; function call to construct array ; Driver code
def arrayConstruct ( N ) : NEW_LINE INDENT for i in range ( 2 , N + 1 , 2 ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT for i in range ( 1 , N - 1 , 2 ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT print ( N - 1 + ( N // 2 ) ) NEW_LINE DEDENT def createArray ( N ) : NEW_LINE INDENT if ( N % 4 == 0 ) : NEW_LINE INDENT arrayConstruct ( N ) NEW_LINE DEDENT else : NEW_LINE INDENT cout << - 1 << endl NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 8 NEW_LINE createArray ( N ) NEW_LINE DEDENT