LC416 - Partition Equal Subset Sum
Problem
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
Input: nums = [1,5,11,5]
Output: true
Explanation: The array can be partitioned as [1, 5, 5] and [11].
Solution
Intuition
Sum array and check if divisible by two to see if possible initially. If it is, the target sum for each subset will be half the total sum. Create a set of possible sums from the entire array (kind of similar to SLP tokenization) and check if target contained in set. If so, return True, else return False. Time and space complexity of this approach is .
Last updated