Identifying Stacks and Queues Patterns
Pre-requisites : Stacks and Queues Operations[push,pop,top/front,empty,size,]
These patterns are based on the different problems identified by me. Viewers can also add their own identified patterns incase those patterns were missed in this article.
In this article , I will discuss the pattern of NGE/NSE
NEXT GREATER ELEMENT(NGE) / NEXT SMALLER ELEMENT(NSE)
On reading the problem statement based on this pattern, you will observe that ,by intuition, the problems require something lesser/greater element either on the next side of element or from the previous side of element.
NOTE: How to identify the problem
You will most probably be given an array.
The problem will ask you to deal with minimum/maximum part/element of the array and then after some basic operations,return the desired output.
Some questions based on this pattern are given below :
https://practice.geeksforgeeks.org/problems/immediate-smaller-element1142/1
https://practice.geeksforgeeks.org/problems/number-of-nges-to-the-right/1
I have solved these problems and worked on the same pattern.
It is important to note that problems 5 and 7 require a thorough understanding of how to apply the NGE/NSE pattern effectively. I will be glad if you share your solutions of Problem 5 and 7 in the comment.
In my next article, I will be discussing the patterns of stacks and queues, where we will identify more problems and their patterns.
"Please provide me with feedback on how I can improve my upcoming articles and any shortcomings you noticed in this article. This will help me to enhance the quality of my future articles."