Uber HackTag 2.0 | Partition Sequences
Anonymous User
852
You are given an integer sequence X of length N,
X = {X[0], X[1], X[2] ......X[N-1]}

You have to pick 3 integers i, j, k such that 0 <= i < j < k < N

Let A, B, C and D be the continuous subsequence sums of X defined as follows :

A = X[0]  + ..........+ X[i]
B = X[i+1] + .......  + X[j]
C = X[j+1] + .......  + X[k]
D = X[k+1] + .......  + X[N-1]

Find the minimum possible value of max(A,B,C,D) - min(A,B,C,D) ?

Constraints :
1 <= X[i] <= 10^9
4 <= N <= 2*10^5

Example 1 :
N = 5
X = {4,3,5,2,3}
Ans : 2 
( Partition X into {4}, {3}, {5}, {2,3} )

Example 2 :
N = 7
X = {3,2,11,12,5,5,9}
Ans : 7
( Partition X into {3,2,11}, {12}, {5,5}, {9} )
Comments (7)