text: Minimize consecutive removals of elements of the same type to empty given array | Function to count minimum consecutive removals of elements of the same type ; Sort the array ; Stores the maximum element present in the array ; Stores sum of the array ; Calculate sum of the array ; Driver Code ; Function call
code: function minRemovals ( A , N ) { A . sort ( ) ; let mx = A [ N - 1 ] ; let sum = 1 ; for ( let i = 0 ; i < N ; i ++ ) { sum += A [ i ] ; } if ( sum - mx >= mx ) { document . write ( 0 ) ; } else { document . write ( 2 * mx - sum ) ; } } let A = [ 3 , 3 , 2 ] ; let N = A . length ; minRemovals ( A , N ) ;