1147. Equal Partition Subset Sum

EasyDynamic Programming0/1 Knapsack

Given an array nums of positive integers, determine whether it can be partitioned into two subsets with equal sums. Return true or false. The input is JSON {nums}.

Input: JSON {nums}.

Output: Boolean — true or false.

Examples

Example 1
Input: {"nums":[1,5,11,5]}
Output: true
Explanation: [1,5,5] and [11].
Example 2
Input: {"nums":[1,2,3,5]}
Output: false
Explanation: Odd total cannot split evenly.
Example 3
Input: {"nums":[2]}
Output: false
Explanation: Cannot split one element.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →