Walmart | OA | Minimum Absolute Sum of Generated Sequences
Anonymous User
580

Given a sequence X of length N.

Generate two sequence Y and Z of length N such that:

  • Y is a non-decreasing sequence
  • Z is a non-increasing sequence
  • X[i] = Y[i] + Z[i]

Output the minimum value of | Y[1] | + ... + | Y[N] | + | Z[1] | + ... + | Z[N] |.

Example :

Input :
3 // N
1 -2 3 // X[]

Output :
10
(Taking Y=[0, 0, 5] and Z=[1,-2,-2])

Can someone tell how to solve this question?

Comments (2)