0
$\begingroup$

Given an array of integers A, the previous smaller element problem is to find, for each position i in the array, the closest element before position i that is smaller than A[i]. This problem can be solved in linear time using a monotone stack. We consider a variant of this problem:

Given an array of integers A, and a positive integer M, for each position i in the array, find the closest element before position i-M that is smaller than A[i].

Can this problem be solved in linear time? We can modify the monotonic stack approach to obtain a linearithmic time algorithm, but I am unable to improve it to linear time.

asked Oct 19 at 2:53
$\endgroup$

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.