Getting wrong output in testcase 4
please modify my code
Stock Span Problem
You are storing the values in the stack and removing them if the the value of the top element is less than the value A[i] and adding the number of the popped values as the answer.
So the approach of adding the number of popped values as the answer is wrong.
6
30
35
38
40
35
50is the array
your algo will give the answer 1 2 3 4 1 3 END
while the expected answer is: 1 2 3 4 1 6 END
Sol: Store the indices at the place of values and pop the index when the top value is less than the A[i].
The number of stocks less than will be i- s.top().
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.