Given an array of distinct positive integers nums and a target, return how many ordered sequences of numbers from nums add up to target. A number may be used any number of times, and different orders count as different sequences, so (1, 2) and (2, 1) are two answers. The answer fits in a 32-bit integer.
Given an array of distinct positive integers nums and a target, return how many ordered sequences of numbers from nums add up to target. A number may be used any number of times, and different orders count as different sequences, so (1, 2) and (2, 1) are two answers. The answer fits in a 32-bit integer.
Example 1:
Input: {"nums":[1,2,3],"target":4}
Output: 7
Constraints:
1≤nums.length≤200
1≤nums[i]≤1000
All the elements of nums are unique.
1≤target≤1000
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[1,2,3],"target":4}
nums
1
2
3
target 4
dp[i] will count the ordered sequences that sum to i. dp[0] = 1: the empty sequence is the one way to make 0.