How to optimally divide an array into two subarrays so that sum of elements in both are same, otherwise give an error?

前端 未结 22 1067
一生所求
一生所求 2020-12-02 11:20

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

22条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 12:08

    This is called partition problem. There are optimal solutions for some special cases. However, in general, it is an NP-complete problem.

提交回复
热议问题