Partition Equal Subset Sum
Medium · Array, Dynamic Programming
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.
Example 1
Input: nums = [1,5,11,5] Output: true
The array can be partitioned as [1, 5, 5] and [11].
Example 2
Input: nums = [1,2,3,5] Output: false
The array cannot be partitioned into equal sum subsets.
Constraints
- 1 <= nums.length <= 200
- 1 <= nums[i] <= 100
Starter code (python)
class Solution(object):
def canPartition(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
Related problems
- Two Sum (Easy)
- Median of Two Sorted Arrays (Hard)
- Longest Palindromic Substring (Medium)
Previous: Add Strings · Next: Battleships in a Board · All problems
Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.