Sponsored
Sponsored
Solve with full IDE support and test cases
Use these hints if you're stuck. Try solving on your own first.
If there is a subsequence of length <code>j</code> with the sum of elements <code>k</code>, it contributes <code>2<sup>n - j</sup></code> to the answer.
Let <code>dp[i][j]</code> represent the number of subsequences in the subarray <code>nums[0..i]</code> which have a sum of <code>j</code>.
We can find the <code>dp[i][k]</code> for all <code>0 <= i <= n-1</code> and multiply them with <code>2<sup>n - j</sup></code> to get final answer.