Stock span problem?

how we came to know stack would be used in this question?

Well using stack for nearest greatest element towards right or left is a well known problem.
This is the case with every data structure. You need to practice and learn theory about which data structure can be used where. You can practise more problems here for stack https://www.hackerearth.com/practice/data-structures/stacks/basics-of-stacks/practice-problems/

which problem are you talking about ?

I am talking about the stack problems in general , which use this concept. There are quite a few in there which use this concept.

1 Like