cannot pass one test case, it gives wrong ans
Stock span problem
@S19WDPP0014
your code is wrong, check this for eg:- arr[] = 10 20 3 30 40 50
answer should be 1 2 1 4 5 6.
Here maintain the stack to store the index of just previous element for current index element and then the difference between their index will tell you the answer.
its still not passing 1 case after the correction, also what should be the output for 111111 ? 1 2 3 4 5 6 right ?
@S19WDPP0014
Have a look at my code. I have commented it for better explanation.
In this solution i am just trying to maintain for current i, the index of last greater element than current i at the top of stack
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.