I was solving a problem on HackerEarth which is as follows:
You are provided an array A of size N that contains non-negative integers. Your task is to determine whether the number that is formed by selecting the last digit of all the N numbers is divisible by 10. Print “Yes” if possible and “No” if not.
Here’s what I did:
size = int(input())
integers = input()
integers = [i for i in integers.split(' ')]
last_digit = [i[-1] for i in integers]
number = int(''.join(last_digit))
if number % 10 == 0:
print("Yes")
else:
print("No")
The code seems correct to me, but the problem is that the online HackerEarth platform throws a runtime error NZEC, about which I have no idea. So, I want to know why(and what kind of) error occured here and what is the problem with my code.
user26346636 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4
https://help.hackerearth.com/hc/en-us/articles/360002673433-types-of-errors
Hackerearth says
For interpreted languages like Python, NZEC will usually mean
-
Usually means that your program has either crashed or raised an uncaught exception
-
Many runtime errors
-
Usage of an external library that is not used by the judge
For your case:
number = int(''.join(last_digit))
number
is becoming a very very big number which is the reason you are getting NZEC error (they have limited memory and time to execute the problem)
little modified code:
size = int(input())
integers = input()
integers = [i for i in integers.split(' ')]
last_digit = [i[-1] for i in integers]
number = ''.join(last_digit) # keeping the number as string
if number[-1] == '0': # checking the last digit of the string to be 0
print("Yes")
else:
print("No")
3