tusharjape007's blog

By tusharjape007, history, 5 years ago, In English

I recently encountered a question on a contest organised by CodeNation which is as follows.

You have been give an array comprising of numbers (ranging from -10^9 to +10^9) and the value of an array is defined as the sum of the absolute differences between each pair of consecutive entries in the array. You are allowed to reverse a contiguous subarray of the given array. What would be the maximum possible value of the array if you apply the given operation utmost once?

I am stuck on the O(n^2) approach to this problem. Can anyone please help me out?

Full text and comments »

  • Vote: I like it
  • +7
  • Vote: I do not like it