You are not logged in. Please login at to post your questions!


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:

Please suggest how to approach this problem.

asked 23 May '18, 22:18

lakh's gravatar image

accept rate: 23%

edited 23 May '18, 22:54

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。


answered 23 May '18, 22:54

freeloop's gravatar image

accept rate: 47%

Thanks for the help mr. freeloop.

(23 May '18, 22:58) lakh3★

exactly man... :)
I just opened this tab for writing that answer..

(23 May '18, 23:06) l_returns4★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 23 May '18, 22:18

question was seen: 143 times

last updated: 26 May '18, 15:47