Grokking Advanced Coding Patterns for Interviews
Ask Author
Back to course home

0% completed

Solution: Range Minimum Query

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 is 1.

.....

.....

.....

Like the course? Get enrolled and start learning!