How to optimally divide an array into two subarrays so that sum of elements in both are same, otherwise give an error?
How to optimally divide an array into two subarrays so that sum of elements in both subarrays is same, otherwise give an error? Example 1 Given the array 10, 20 , 30 , 5 , 40 , 50 , 40 , 15 It can be divided as 10, 20, 30, 5, 40 and 50, 40, 15 Each subarray sums up to 105. Example 2 10, 20, 30, 5, 40, 50, 40, 10 The array cannot be divided into 2 arrays of an equal sum. Gal There exists a solution, which involves dynamic programming, that runs in O(n*TotalSum) , where n is the number of elements in the array and TotalSum is their total sum. The first part consists in calculating the set of all