Challenge 3: The Partition Problem

Let's write code to solve the partition problem!

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. You can 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

int arr[] = {1, 2, 3, 4};
int n = 4; // size

Sample Output

1

Coding Exercise

Take a close look and design a step-by-step algorithm before jumping on 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 hint and solution provided in the code tab. Good Luck!

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