Next Larger/ Smaller element (using Monotonic Queue)

In this article, we are going to discuss the various approaches to solve the Next Larger/ Smaller element problem. In this problem, we are given an array and our task is to find the next larger/ smaller element for each element in the array. If there is no larger/ smaller element to the right then return -1.

For example:

Array -> 8 5 2 3 9.Next larger element -> 9 9 3 9 -1.Next smaller element -> 5 2 -1 -1 -1.Array -> 18 25 2 13 29.Next larger element -> 25 29 13 29 -1.Next smaller ele...
 •  0 comments  •  flag
Share on Twitter
Published on April 26, 2021 10:52
No comments have been added yet.