Static Range Maximum Query

Given a static array nums, return the maximum value for each queried interval. Since the data never changes, preprocessing can answer many range maximum queries efficiently, making this a standard advanced tree-style range query problem.

Input Format

nums = static integer array, queries = range maximum requests

Output Format

maximum 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 = [2,5,1,4,9,3]
queries = [[0,3],[1,4]]

Output:

[5,9]

Explanation:

The maximum in the first interval is 5, and the maximum in the second interval is 9.

Example 2:

Input:

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

Output:

[7]

Explanation:

The largest value in the array is 7.

Loading...
Static Range Maximum Query - Advanced Trees