952. Range Minimum Query (Segment Tree)

HardTreesSegment TreeRange QuerySparse Table

Given an integer array and a list of range queries [l, r], return the minimum element in each range (inclusive), using a segment tree (or sparse table). Return the answers as an array in order. The input is JSON {nums, queries}.

Input: JSON {nums, queries}.

Output: Array — the minimum for each query.

Examples

Example 1
Input: {"nums":[5,2,8,1,9,3],"queries":[[0,2],[1,4],[3,5]]}
Output: [2,1,1]
Explanation: Range minimums.
Example 2
Input: {"nums":[7],"queries":[[0,0]]}
Output: [7]
Explanation: Single element.
Example 3
Input: {"nums":[3,1,4,1,5],"queries":[[0,4],[2,3]]}
Output: [1,1]
Explanation: Two ranges.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →