
If the given array is [6,7,1,8,5]. We can split the array into [6,7,1] and [8,5].
Hence the answer will be |14-13| = 1 which is minimum.
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains a single integer, 'N,’ denoting the number of elements in 'ARR'.
The second line of each test case has ‘N’ integers corresponding to the elements of 'ARR'.
For each test case, print a single integer corresponding to the minimum absolute difference possible.
Print the output of each test case in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^6
-10^3 <= 'ARR'[i] <= 10^3
Time limit: 1 sec
In this approach, we will first store the prefix sum of the given array 'ARR' into an array 'PREFIXSUM'. 'PREFIXSUM'[i] denotes the sum of all elements from index 0 to i.
Now, We will compute the sum of both the subarrays using the 'PREFIXSUM' array and compare the minimum absolute difference.
In this approach, we will first store the sum of all elements in an integer 'TOTALSUM'.We will declare a variable 'CURRENTSUM' to store the sum of the first subarray and the sum of the remaining array will be computed as 'TOTALSUM' - 'CURRENTSUM'. Now we will compare the minimum absolute difference for each index.