377_Combination Sum IV
Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.
Example:
Solution:
Idea:
Use the previous example, to get the number of possible combinations for target 4, we need the number of combinations to get target 4-1=3, 4-2=2 and 4-3=1.
We can store the number of combinations to get 1, 2, 3, 4 for reducing replicated computations.
Time Complexity: where m is the target number, n is the length of possible numbers
Space Complexity:
Follow up: What if negative numbers are allowed in the given array? How does it change the problem? What limitation we need to add to the question to allow negative numbers?
Last updated