Static Range Minimum Query

medium · sparse-table, range-query, array

Static Range Minimum Query

You are given an array nums and a list of queries. Each query is [left, right] (0-indexed, inclusive). Return the minimum value in each range.

The array never changes.

Function signature

func StaticRangeMin(nums []int, queries [][]int) []int

Example

nums = [4,1,7,0,3]
queries = [[0,2],[1,3],[3,4]]
output = [1,0,0]

Constraints

  • 0 <= len(nums) <= 200_000
  • 0 <= len(queries) <= 200_000
  • 0 <= left <= right < len(nums)
  • -1_000_000_000 <= nums[i] <= 1_000_000_000

Notes

  • A sparse table answers range min queries in O(1) after O(n log n) preprocessing.
Run tests to see results
No issues detected