Answer the question
In order to leave comments, you need to log in
How to split an array into two subarrays?
It is necessary to split the array into two parts so that the sum of the elements is equal. The number of elements in subarrays can vary. For example: there is an array A={1, 1, 1, 1, 4}. It should split into two B={1, 1, 1, 1} and C={4}. It is possible, even better, without code, only an algorithm.
Answer the question
In order to leave comments, you need to log in
Partition problem .
There is a lot of information on google regarding this.
Most in the forehead for O (N):
1) we go with one iterator on the right, the other on the left, until they collide.
2) if the right side is smaller, then continue moving to the left until there are equal sums or reach the beginning of the array
3) if the left side is smaller, then continue moving to the right until there are equal sums or reach the end of the array
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question