dp of size n with all elements set to -1.dp[0] to 0.0 to n-1.
a. If dp[i] is -1, continue to the next iteration.
b. For each index j from i+1 to n-1, check if nums[j] is within the target range from nums[i].
c. If it is, update dp[j] to the maximum of dp[j] and dp[i] + 1.dp[n-1] is -1, return -1.dp[n-1].