Minimize the sum of absolute difference of adjacent array elements

Given an array A of N (N<=10^6) elements , you can choose any subarray and invert the sign of all elements lying in that subarray i.e positive elements are changed to negative and vice versa.

You have to apply this operation exactly once. Determine the minimum possible sum of absolute difference of adjacent array elements that can be obtained after applying the operation exactly once. -10^9<=A[i]<=10^9.

Link to problem: Problem - I - Codeforces

Please suggest how to approach this problem.

Hi, I met you again, tips: when flipping symbols in the interval [L, R], the effect on the answer only exists at the endpoint, for example, when flipping the entire array, the answers was not changed. so the next steps are obvious。

2 Likes

Thanks for the help mr. freeloop.

exactly man… :slight_smile:
I just opened this tab for writing that answer…

1 Like