Runtime error

http://www.codechef.com/viewsolution/2182524 here is my code it is giving Runtime error, what to do in such type of errors n how can i eradicate from this code???
Again I m getting the same error in the next problem , in that i m not using a lot more space still it is giving runtime error…Please Do HELP!!!
here’s the code http://www.codechef.com/viewsolution/2182959.

Hello @aasthi,

There are several types of Runtime errors your code can generate and you can read all about them on the FAQ section, here.

Try to look for something in your code which might cause the runtime error and fix it!!

If you can’t, then try to rewrite your code with a different approach or different data structure, I guess that might sound silly, but, sometimes, it helps :slight_smile:

Best regards,

Bruno

@aasthi…assume if the length of the string i.e. n in ur code equals 6…then you are creating a boolean array of 10^(6+2) i.e 10^8 which is not possible…and that will give you a Runtime Error!!!

1 Like

and it is the same if n==7…u r creating an array of 10^8 cells…which is not possible!!!

i m having a look at your code…till then u can see my code(AC) which i just wrote (in c++) for “cleaning up”…!!

This is your corrected code…i changed bufferedReader to Scanner…i did so as there may be empty lines in the input cases so the readLine() function reads that and then when u split then there is no array…also if u dont split then you convert “” to integer which will give number format exception…!!! In such cases you need to take input carefully!!!

One way is that you keep on reading the input, using readLine(), till it no longer is equal to “”…!!!

1 Like