Minimum increments required to make absolute difference of all pairwise adjacent array elements even | Function to find the minimum number of increments of array elements required to make difference between all pairwise adjacent elements even ; Stores the count of odd and even elements ; Traverse the array ; Increment odd count ; Increment even count ; Return the minimum number of operations required ; Driver code
function minOperations ( arr , n ) { var oddcount = 0 , evencount = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 1 ) oddcount ++ ; else evencount ++ ; } return Math . min ( oddcount , evencount ) ; } var arr = [ 2 , 4 , 3 , 1 , 8 ] ; var N = arr . length ; document . write ( minOperations ( arr , N ) ) ;