Quiz2 Dynamic programming

Q9. DP9
Given an array A consisting of n integers , we define beauty of the array as maximum sum of some contiguous elements with performing atmost one operation which is , you can multiply any subarray with ‘x’ but only once.

What will be the maximum subarray sum for this input

N=5,x=-2

A=[-3,8,-2,1,-6]

(Bonus :: Can you write the effiicient code for it ?)

How the answer for this is given as 22? Please tell

Hey @adarsh_2001
multiply the subarray
-2 1 -6 by x
u get
-3 8 4 -2 12
take the sum of
8 4 -2 12
which is 22
that is the answer
]

1 Like