Efficient range maximum/minimum query.
npm install 1d-range-query
import rangeQuery from '1d-range-query';
const query = rangeQuery([1,5,10,2,5,3]);
console.log(query.max(0, 2)); // => 10 (10 is the max in [1,5,10])
console.log(query.min(2, 4)); // => 2 (2 is the min in [10,2,5])
Query the maximum value in range [from, to]
.
Query the minimum value in range [from, to]
.
Initialize: O(nlogn)
Query: O(1)
O(nlogn)
MIT