Balance The Array
Given an array of integers, determine if it is possible to split the array into two subarrays such that the sum of the elements in both subarrays is the same. Return true if it is possible, otherwise return false.
[ [ 1, 2, 3, 4, 10 ] ]
Explanation. We can split the array into [1, 2, 3, 4] and [10], where both subarrays have a sum of 10.
[ [ 1, 2, 3 ] ]
Explanation. There is no way to split the array such that both sections have equal summation.
[ [ 10, -5, 5, 10 ] ]
Explanation. The array can be split into [10, -5] and [5, 10], where both have the sum of 5.
[ [ 0, 0, 0, 0 ] ]
Explanation. The array can be equally divided in multiple ways as all elements are zero.
[ [ 100, 200, -150 ] ]
Explanation. It's not possible to split the array into two parts with equal sums.
Follow-up: How would you handle the case if the elements can also include floating point numbers?
1. The array will contain at least one element and at most 100 elements.\n2. Each array element is an integer between -1000 and 1000.
- Views
- 1