wrote the code for stock span, unable to understand the problem
1 test case pending
Hi @pgarg,
stock span is a standard stack problem. The logic which u r implementinng in ur code is not correct.
Pls refer to the stock span lecture inorder to understand the question better and get idea about the approach (both naive and optimised) which can be used to solve the question.
Hope dis resolve ur doubt. If u still have any queries, feel free to post them here.
I am doing it without stacks and want to know the error in my code it works for 3/4 test cases
Hi @pgarg,
Sorry for late Reply.
for input n=4, array={1,2,1,4}, ur code gives
output as 1 2 1 2 END
whereas expected ouput is 1 2 1 3 END.
Hope dis clears why use of stack is required in order to solve dis question in O(n) complexity.
If its still not clear, please feel free to post ur doubts here.