Given a sequence S
of n
integer elements, I need a function min(i,j)
that finds the minimum element of the sequence between index i and index j (both inclusive) such that:
- Initialization takes
O(n)
; - Memory space
O(n)
; min(i,j)
takesO(log(n))
.
Please suggest an algorithm for this.