Minimum elements to be removed such that sum of adjacent elements is always odd | Returns the minimum number of eliminations ; Stores the previous element ; Stores the new value ; Check if the previous and current values are of same parity ; Previous value is now the current value ; Return the counter variable ; Driver code
function min_elimination ( n , arr ) { let count = 0 ; let prev_val = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { let curr_val = arr [ i ] ; if ( curr_val % 2 == prev_val % 2 ) count ++ ; prev_val = curr_val ; } return count ; } let arr = [ 1 , 2 , 3 , 7 , 9 ] ; let n = arr . length ; document . write ( min_elimination ( n , arr ) ) ;