Example:
input = [2, 3, 3, 4, 5]
sumTargets = [8, 6, 3]
I want an algorithm to partition the input
into subsets whose elements sum to the targets, in this case 8, 6 and 3. Both input
and sumTargets
can be of any size and it only needs to return one possible set of subsets. Example output:
[ [3, 5], [2, 4], [3] ]
I’ve seen simpler subset problems in the past so thought of following a similar approach using recursion, but I was using two recursive methods and it was getting messy. Before I continue down the rabbit hole I was wondering if there is a simpler approach for this?
You need to sign in to view this answers