Maximum sum obtained by dividing Array into several subarrays as per given conditions | Function to find the required answer ; Stores maximum sum ; Adding the difference of elements at ends of increasing subarray to the answer ; Input ; Function calling
function maximumSum ( arr , N ) { let Sum = 0 ; for ( let i = 1 ; i < N ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) Sum += ( arr [ i ] - arr [ i - 1 ] ) ; } return Sum ; } let arr = [ 1 , 5 , 3 ] ; let N = arr . length ; document . write ( maximumSum ( arr , N ) ) ;