Minimum operations required to make all elements in an array of first N odd numbers equal | Java program for the above approach ; Function to find the minimum number of operations required to make the array elements equal ; If the value of N is even ; Return the value ; Otherwise , N is odd ; Return the value ; Driver Code
class GFG { public static int minOperation ( int N ) { if ( N % 2 == 0 ) { return ( N / 2 ) * ( N / 2 ) ; } int k = ( N - 1 ) / 2 ; return k * ( k + 1 ) ; } public static void main ( String [ ] args ) { int N = 6 ; System . out . println ( minOperation ( N ) ) ; } }