I am Not able to understand why I am getting a runtime error for my solution

Hello CodeChef
I was practicing and I solved a problem:
(link:https://www.codechef.com/IARCSJUD/problems/BOOKLIST
When I test my solution in my local machine it doesnot give any erroe but when I run it It give me runtime error
This is my solution (Its in Python3):
https://www.codechef.com/viewsolution/39157161

can someone please help me!

I could not figure out why is your code giving NZEC error but when I submitted my solution using the function you have used i.e remove, it is giving TLE for some sub tasks.
While for the same solution, if I use the pop function, it passes all the test cases.

You can see my both submissions here.

https://www.codechef.com/viewsolution/39158322 -> TLE
https://www.codechef.com/viewsolution/39158140 -> AC

1 Like

Thanks a lot! @aryan_129 I will try using pop and get back if still I get any problem!
Thanks a lot again!!

I tried the solution @aryan_129 and found out the mistake , there is a space after the last number in the space separated book list so when I do input().split*(" “) as there is nothing after the space after the " " so it was giving NZEC So inorder to fix this you have to do input().strip(” “).split(” ").
Thought to tell you about it too!!

1 Like

I was really frustrated after seeing the solution multiple times and not finding any error.
Thanks for telling me about strip method. In my opinion, always use list directly instead of taking input as string and then converting it to list, this will make sure that there are no unnecessary spaces without explicitly using other functions like rstrip, lstrip or strip.

1 Like