I was trying to implement Stock Span Problem(For DCGAME). I coded the solution but getting runtime error. Please help me. I’m unable to find the error. Here’s my

[1]. Thanks in advance :)


I found the a bug in your code at line no. 130.

The reason for run time error even though you have added a check for empty stack is that you are accessing top of stack when it is empty in while as a[i]>[] before you are checking for size of stack.

Always check for the size before accessing stacks or arrays in condition for while().

Your code with small edit

Hope this helps you. :slight_smile: