Reputation: 23
Preprocess an array A in O(n log n) time so that you can answer queries of the form findmax(i,j): find the maximum value in an interval [i; j] (that is, the maximum value among the array elements A[i],A[i + 1],...,A[j]) in O(1)) time per query.
Additional question: Show how to preprocess in O(n) time so that you can answer the above queries in O(log n) time.
Upvotes: 0
Views: 462