the method in the video is also O(N^2)
Span problem doubt
Hi @deepakjumani09, the time complexity is O(n) , think is this way every element is pushed in the stack once only and popped from the stack only once so, if we have n stock prices then all the indexes are pushed and popped once so overall operation taking place is 2*n thus making the complexity O(N).
try to dry run the code yourself you will get what i am saying
In case u encounter any problem feel free to ask
mark your doubt as resolved if you got the answer
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.