We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
see, you are adding sum to a[p] and adding negative sum at a[q+1]. which make sure that when you add element from a[p] to a[q] sum is added only once and it should be subtracted at a[q+1] as this sum span from p to q only.
Rest array element are either 0 or some other input sum.
max of addition will be output.
refer to above code for p, q, and sum.
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
see, you are adding sum to a[p] and adding negative sum at a[q+1]. which make sure that when you add element from a[p] to a[q] sum is added only once and it should be subtracted at a[q+1] as this sum span from p to q only. Rest array element are either 0 or some other input sum. max of addition will be output. refer to above code for p, q, and sum.