Range Queries Sparse table
606. Range Minimum Queries
You are given an array of integers nums and a list of queries, where queries[i] = [l, r].
The answer to a query is the smallest value among nums[l], nums[l + 1], …, nums[r]. Both ends are included,
and positions count from 0. The array does not change between queries.
Return the answers in the same order as queries.
Example 1
Input: nums = [4, -2, 7, 3, -5, 6, 1]
queries = [[0, 2],
[2, 5],
[3, 3],
[0, 6],
[5, 6]]
[-2,-5,3,-5,1]Explanation: [0,2] covers 4, -2 and 7, so its answer is -2. [2,5] covers 7, 3, -5 and 6. [3,3] holds only 3.
The whole array [0,6] has -5 as its minimum, and [5,6] covers 6 and 1.
Example 2
Input: nums = [1000000000, -1000000000, 0]
queries = [[0, 0], [0, 2], [2, 2]]
[1000000000,-1000000000,0]Explanation: A range of one position has that value as its minimum. The whole array holds -109.
Example 3
Input: nums = [8, 3, 3, 9]
queries = [[0, 3], [0, 3], [3, 3]]
[3,3,9]Explanation: The same query can appear twice, and each copy gets its own answer. The answer is the smallest value, so it is 3 even though 3 appears twice.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ nums.length ≤ 105-109 ≤ nums[i] ≤ 1091 ≤ queries.length ≤ 105queries[i].length = 20 ≤ l ≤ r < nums.length
Clarifying questions
What you would ask an interviewer before writing any code.