Static Range Minimum Query

Given a static array nums, return the minimum value for each queried interval. Range minimum queries are one of the classic use cases for segment trees and sparse tables when the underlying array does not change.

Input Format

nums = static integer array, queries = range minimum requests

Output Format

minimum for each query, in order

Constraints

  • 1 <= nums.length <= 10^5
  • 1 <= queries.length <= 10^5
  • Each query is [left, right] with 0 <= left <= right < nums.length.

Examples

Example 1:

Input:

nums = [5,2,6,3,1]
queries = [[0,2],[2,4]]

Output:

[2,1]

Explanation:

The minimum in the first interval is 2, and the minimum in the second interval is 1.

Example 2:

Input:

nums = [9,8,7,6]
queries = [[1,3]]

Output:

[6]

Explanation:

The smallest value in nums[1..3] is 6.

Loading...
Static Range Minimum Query - Advanced Trees