Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Imagine the array is empty, and each element is coming to its index one by one, starting with the smallest element.
For each coming element nums[i], calculate L and R, the indices of the first smallest elements on the left and the right respectively.
The answer of the queries from 1 to R-L+1 will be at least this element.