You are given a strictly increasing zero indexed integer array nums of length queries where each query is given as queries[i]
For any index i, its closest neighbor is defined as the adjacent index j (where nums[i] nums[j]
When moving directly from index i to an adjacent index j:
The cost is j is the closest neighbor of i.
The cost is nums[i] nums[j]
For each query queries[i] l_i to index r_i by moving only between adjacent indices.
Return an integer array ans where ans[i] is the minimum cost for the $i$th query.
Constraints:
nums.length
nums[i]
nums is strictly increasing
queries.length
queries[i]
nums.length
You are given a strictly increasing zero indexed integer array nums of length queries where each query is given as queries[i]
For any index i, its closest neighbor is defined as the adjacent index j (where nums[i] nums[j]
When moving directly from index i to an adjacent index j:
The cost is j is the closest neighbor of i.
The cost is nums[i] nums[j]
For each query queries[i] l_i to index r_i by moving only between adjacent indices.
Return an integer array ans where ans[i] is the minimum cost for the $i$th query.
Constraints:
nums.length
nums[i]
nums is strictly increasing
queries.length
queries[i]
nums.length