dp with dimensions (len(nums) + 1) x (max(nums) + 1) filled with zeros.dp such that dp[i][j] represents the count of number j up to index i-1 in nums.[li, ri], create a list present of numbers that are present in the subarray by comparing dp[ri+1] and dp[li].present and iterate through it to find the minimum absolute difference between consecutive numbers.present has less than two elements, the result for the query is -1.ans and return it.