Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Partition Equal Subset

Easy Acceptance 77.00% Points 20.00

The Partition Equal Subset problem requires determining whether a given array of positive integers can be divided into two subsets such that the sum of elements in both subsets is equal. Each element must belong to exactly one subset. The task is to return true if such a partition is possible, otherwise return false.

Examples
Example 1

Example 1

Input: nums = [1,5,11,5]

Output: true

Explanation: The total sum of the array is 22. It can be divided into two subsets with sum 11 each, for example [1,5,5] and [11]. Therefore, equal partition is possible.

Example 2

Example 2

Input: nums = [1,2,3,5]

Output: false

Explanation: The total sum is 11, which is odd. Since it cannot be divided into two equal integer parts, partition is not possible.

Example 3

Example 3

Input: nums = [2,2,1,1]

Output: true

Explanation: The total sum is 6. It can be split into two subsets with sum 3 each, for example [2,1] and [2,1]. Therefore, equal partition exists.

Hints
Hint 1
N/A
Constraints
  • 1 = n = 200
  • 1 = nums[i] = 100
Companies
Apple
Topics
Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions