Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Use dynamic programming.
Let <code>dp[i][j]</code> be the maximum length of any subsequence of <code>nums[0..i - 1]</code> that sums to <code>j</code>.
<code>dp[0][0] = 1</code>, and <code>dp[0][j] = 1</code> for all <code>target ≥ j > 0</code>.
<code>dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - nums[i -1])</code> for all <code>n ≥ i > 0</code> and <code>target ≥ j > nums[i - 1]</code>.