Minimum value of " max ▁ + ▁ min " in a subarray | java program to find sum of maximum and minimum in any subarray of an array of positive numbers . ; Driver code
function maxSum ( arr , n ) { if ( n < 2 ) return - 1 ; let ans = arr [ 0 ] + arr [ 1 ] ; for ( let i = 1 ; i + 1 < n ; i ++ ) ans = Math . min ( ans , ( arr [ i ] + arr [ i + 1 ] ) ) ; return ans ; } let arr = [ 1 , 12 , 2 , 2 ] ; let n = arr . length ; document . write ( maxSum ( arr , n ) ) ;