Challenge: The Partition Problem

Check if the array can be partitioned into two subsets with equal sums.

Problem statement

Given an array of integers, write a function to find if any two subsets of the input array exist such that the sum of both subsets is equal. Assume that the array will only consist of positive integers.

Input

An array of positive integers.

Output

A boolean; true if such subsets exist and false if they do not.

Sample input

 set = {1, 2, 3, 4}; 

Sample output

result = true; // (The 2 subsets will be 1,4 & 2,3)

Coding Challenge

First, take a close look at this problem and design a step-by-step algorithm before jumping to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the solution provided in the solution section. Good luck!

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.