why it is O(N) , there is possiblity that for any index i we don’t have a prev largest element, that time we have to pop every number from stack until it becomes empty.
therefore time complexity should be in order of N^2.
ex: [ 10 8 9 50 ] ,
for 50 all the prev number (9,8,10) should be popped from stack. But sir said that there will be only 1 push or 1 pop for any index?