A sparse table precomputes the minimum over every range of length for all starting positions. For each index and power , store st[i][k] = min(tourDepth[i], ..., tourDepth[i + 2^k - 1]). To query , find the largest such that .
The answer is min(st[l][k], st[r - 2^k + 1][k]). These two ranges overlap but cover . Preprocessing takes , queries take .
Space complexity is for the data structures used.