Top 150 InterviewMedium

Partition Equal Subset Sum

Detailed guide and Python implementation for the 'Partition Equal Subset Sum' problem.

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?
Consider using 1D DP-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

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

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.