Back to course home
0% completed
Vote For New Content
Range Minimum Query (easy)
Problem Statement
You are given an array nums
containing n
integers and a 2D array queries
of length q
, where queries[i] = [start<sub>i</sub>, end<sub>i</sub>], representing a starting and ending range (inclusive).
Return an array of size q
, where each element is the minimum
value in the respective range from nums
.
Examples
Example 1:
- Input: nums = [2, 6, 1, 12, 9, 5, 3, 7], queries = [[0, 3], [2, 5], [0, 1], [3, 7], [0, 7], [4, 6], [4, 5]]
- Output: [1, 1, 2, 3, 1, 3, 5]
- Justification:
- For the range
[0, 3]
, the minimum is1
. - For the range
[2, 5]
, the minimum is1
. - For the range
[0, 1]
, the minimum is2
. - For the range
[3, 7]
, the minimum is3
. - For the range
[0, 7]
, the minimum is1
. - For the range
[4, 6]
, the minimum is3
. - For the range
[4, 5]
, the minimum is5
.
- For the range
Example 2:
- Input: nums = [4, 8, 6, 2, 10, 15], queries = [[1, 3], [0, 2], [2, 4], [3, 5]]
- Output: [2, 4, 2, 2]
- Justification:
- For the range
[1, 3]
, the minimum is2
. - For the range
[0, 2]
, the minimum is4
. - For the range
[2, 4]
, the minimum is2
. - For the range
[3, 5]
, the minimum is2
.
- For the range
Example 3:
- Input: nums = [11, 13, 5, 8, 10, 12, 7, 14], queries = [[0, 4], [1, 3], [2, 5], [3, 6]]
- Output: [5, 5, 5, 7]
- Justification:
- For the range
[0, 4]
, the minimum is5
. - For the range
[1, 3]
, the minimum is5
. - For the range
[2, 5]
, the minimum is5
. - For the range
[3, 6]
, the minimum is7
.
- For the range
Constraints:
- 0 <= start<sub>i</sub> < end<sub>i</sub> <= 1000
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible