Skip to content
Veltoryx Technologies
ProProblem 82● MediumLeetCode #377 ↗4 min readUpdated 30 October 2026

Combination Sum IV

Find the number of ordered sequences of positive integers that add up to a target sum using dynamic programming.

01The problem

Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target.

The test cases are generated so that the answer can fit in a 32-bit integer.

Note: Unlike Combination Sum I-III, here different sequences count as different combinations. For example, (1, 1, 2), (1, 2, 1), and (2, 1, 1) are treated as three distinct solutions.

InputOutputWhy
nums = [1, 2, 3], target = 47Possible sequences: (1,1,1,1), (1,1,2), (1,2,1), (1,3), (2,1,1), (2,2), (3,1)
nums = [9], target = 30Impossible to form 3 using only 9

Constraints: 1 <= nums.length <= 200, 1 <= nums[i] <= 1000, all elements are unique, 1 <= target <= 1000.

Loading the rest of the lesson…