You are not logged in. Please login at www.codechef.com to post your questions!

×

Stock Span RUNTIME ERROR

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 code. Thanks in advance :)

asked 18 Aug '15, 02:02

arpn's gravatar image

4★arpn
464516
accept rate: 29%

edited 18 Aug '15, 02:03


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]>[st.top()] 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. :)

link

answered 19 Aug '15, 15:23

utkarsh13's gravatar image

4★utkarsh13
2303717
accept rate: 6%

edited 19 Aug '15, 16:08

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×545
×17

question asked: 18 Aug '15, 02:02

question was seen: 740 times

last updated: 19 Aug '15, 16:08