Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Sort <code>nums</code>.
There are at most <code>n<sup>2</sup></code> distinct differences.
For a particular difference <code>d</code>, let <code>dp[len][i][j]</code> be the number of subsequences of length <code>len</code> in the subarray <code>nums[0..i]</code> where the last element picked was at index <code>j</code>.
For each index, we can check if it can be picked if <code>nums[i] - nums[j] <= d</code>.