Code Room
CodingMediumcod-g545
Subject Segment treeLevel Mid–Senior~30 minCommon in Databases & SQL · Algorithms & data structures interviewsIndustries Software development, Technology

Question

Given a static integer array and a list of [l, r] queries, return the minimum of each inclusive range arr[l..r]. The array never changes but there can be up to 1e5 queries, so precompute a sparse table (table[k][i] = min of the 2^k elements starting at i) for O(1) per query via two overlapping power-of-two blocks. Return the list of range minima in query order.

Implement
sparse_table_rmq(arr: list[int], queries: list[list[int]]) → list[int]
Examples
in[[5,2,4,7,6,3,1,2],[[0,3],[2,5],[4,7],[6,6]]]out[2,3,1,1]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.