Back to Practice Dashboard
Top 150 InterviewMedium

Partition Equal Subset Sum

Learn how to solve the 'Partition Equal Subset Sum' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Medium

Given an integer array nums, return True if you can partition the array into two subsets such that the sum of the elements in both subsets is equal, or False otherwise.

Write a function canPartition(nums: List[int]) -> bool.

Constraints
  • 1 <= len(nums) <= 200
  • 1 <= nums[i] <= 100

Examples

Example 1
Input
nums = [1,5,11,5]
Output
True
Explanation

The array can be partitioned as [1, 5, 5] and [11].

Example 2
Input
nums = [1,2,3,5]
Output
False
Explanation

The array cannot be partitioned into equal sum subsets.

Need a Hint?
Define subproblem states, establish the recurrence relation, and use memoization (top-down) or tabulation (bottom-up).
Edge Cases to Watch
  • Empty list or null input variables
  • Single item lists/arrays
  • Extremely large input bounds causing integer or stack overflow

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor