dp
to store the maximum length of subsequence that ends at index right
with a common difference of diff
.right
and left
where left < right
.diff = nums[right] - nums[left]
.dp[right][diff]
to be the maximum of its current value and dp[left][diff] + 1
.