Given an array A[] of size N, the duty is to search out the minimal integer to be appended at any finish within the array to make it equilibrium.
An array is in equilibrium if there exists any index i such that:
sum of A[0, . . ., i1] = sum of A[i+1, . . ., N1]
Instance:Â
Enter: A[] = {5, 2, 6, 4, 3, Â 2}Â
Output: 2Â
Clarification: Within the above array integer 2 is added on the entrance of the array then array change into {2, 5, 2, 6, 4, 3, 2}.Â
Therefore, index 3 is our equilibrium level.Enter: A[] = {0, 6, 3, 4, 9}
Output: 0
Â
Method: The issue will be solved utilizing two pointer strategy as talked about beneath:
 Hold left pointer at begin and the suitable pointer on the finish of the array
 Iterate the next steps until the left and proper pointer change into adjoining:
 If sum of array from begin to left pointer ( = left_sum) is no less than the sum of array from proper pointer to finish ( = right_sum), decrement the suitable pointer by 1
 else increment the left pointer by 1
 On the finish, absolutely the distinction between the suitable sum and left sum would be the required minimal quantity to be added within the given such that the array stays in equilibrium,
Illustration:
Take into account: A[] = {5, 2, 6, 4, 3, Â 2}Â
Initially, left_pointer will level at component 5 and right_pointer will level at component 2
 Since right_pointer will not be adjoining to left_pointer, Iteration 1:
 left_sum = 5 and right_sum = 2,
 since left_sum â‰¥ right_sum, due to this fact shift right_pointer to 1 left (now at component 3)
 Since right_pointer will not be adjoining to left_pointer, Iteration 2:
 left_sum = 5 and right_sum = 5,
 since left_sum = right_sum, due to this fact shift right_pointer to 1 left (now at component 4) and left_pointer to 1 proper (now at component 2)
 Since right_pointer will not be adjoining to left_pointer, Iteration 3:
 left_sum = 7 and right_sum = 9,
 since left_sum < right_sum, due to this fact shift left_pointer to 1 (now at component 6)
 Right here in iteration 4, since right_pointer is adjoining to left_pointer, break the loop and go to subsequent step
 Discover absolutely the distinction between left_sum and right_sum = abs(9 â€“ 7) = 2
Therefore, 2 is the minimal quantity to be added to the array such that it stays in equilibrium.
Under is the implementation of the above strategy:
C++

Time Complexity: O(N)
Auxiliary House: O(1).