< Back to forum

Runtime Error

Why is my code having a runtime error? The question is https://www.codechef.com/problems/CLEANUP and my code is https://www.codechef.com/viewsolution/30697756. Why am I getting runtime error??

Asked by: harsh002jha on March 23, 2020, 8:37 p.m. Last updated on March 23, 2020, 8:37 p.m.


look at line 14 and 15 of your solution

It may occour that p>m and array index range is<m so runtime error will occour as you are accessing out of the array

sharshach last updated on March 28, 2020, 5:52 a.m.

Enter your answer details below:


Preview

Enter your comment details below:

Preview




1 Answer(s)

avatar

Look at line 9 of your solution. Declaring B[m] will give you runtime error in cases where m<n/2

In if else statement(line 23 and 31) value of c can be greater than m

Anonymous last updated on March 29, 2020, 2:35 p.m. 0    Reply    Upvote   

Instruction to write good question
  1. 1. Write a title that summarizes the specific problem
  2. 2. Pretend you're talking to a busy colleague
  3. 3. Spelling, grammar and punctuation are important!

Bad: C# Math Confusion
Good: Why does using float instead of int give me different results when all of my inputs are integers?
Bad: [php] session doubt
Good: How can I redirect users to different pages based on session data in PHP?
Bad: android if else problems
Good: Why does str == "value" evaluate to false when str is set to "value"?

Refer to Stack Overflow guide on asking a good question.