#K43172. Equal Sum Subarrays
Equal Sum Subarrays
Equal Sum Subarrays
You are given an array of integers. Your task is to determine whether it is possible to split the array into two contiguous subarrays (the left subarray and the right subarray) such that the sum of the elements in the left subarray is equal to the sum of the elements in the right subarray.
Formally, let the array be nums and its total sum be \( S \). We want to find an index i (0 < i < n) such that the sum of the first i numbers is \( \frac{S}{2} \). Note that if \( S \) is odd then such a split is impossible (i.e. \( S \mod 2 \neq 0 \)).
If the array is empty or has only one element, the answer is False
.
inputFormat
The first line of the input contains an integer T, representing the number of test cases. Each test case is described as follows:
- The first line contains an integer n --- the number of elements in the array.
- The second line contains n space-separated integers, representing the elements of the array.
For example, the input:
3 4 1 1 1 1 5 2 3 5 5 2 3 -1 0 1
represents 3 test cases.
outputFormat
For each test case, output a single line containing either True
or False
depending on whether the array can be split into two contiguous subarrays with equal sum.
For the above sample input, the correct output is:
True False True## sample
1
4
1 1 1 1
True
</p>