Maximum possible value of array elements that can be made based on given capacity conditions | Function to find the maximum element after shifting operations in arr [ ] ; Stores the sum of array element ; Stores the maximum element in cap [ ] ; Iterate to find maximum element ; Return the resultant maximum value ; Driver Code
function maxShiftArrayValue ( arr , cap , N ) { let sumVals = 0 ; for ( let i = 0 ; i < N ; i ++ ) { sumVals += arr [ i ] ; } let maxCapacity = 0 ; for ( let i = 0 ; i < N ; i ++ ) { maxCapacity = Math . max ( cap [ i ] , maxCapacity ) ; } return Math . min ( maxCapacity , sumVals ) ; } let arr = [ 2 , 3 ] ; let cap = [ 5 , 6 ] ; let N = arr . length document . write ( maxShiftArrayValue ( arr , cap , N ) ) ;