0

Preprocess an array A in O(n log n) time so that you can answer queries of the form fin dmax(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.

2
  • What have you tried so far? Right now it looks like you've copied and pasted this question verbatim from a problem set or coding challenge website, which gives us very little reason to want to help you at all. Commented Feb 24, 2013 at 19:31
  • I have tried DP and this is past year informatics olympiad question. :) Commented Feb 24, 2013 at 19:44

1 Answer 1

2

The problem is known as range minimum (maximum) query - RMQ. The link basically answers both of your questions.

The classic solutions are dynamic programming and segment trees.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.