Hi I am using the following python code and I am getting an NZEC. I cant understand what part is giving the error, i tried as many test cases as i could. Can someone please give me an example testcase for what can cause the error?
import sys
NUMBERS = []
MIN_LENGTH = {}
def init():
global NUMBERS,MIN_LENGTH
NUMBERS = []
MIN_LENGTH = {}
def read_input():
s = sys.stdin
k = int(s.readline())
numbers = []
n = int(s.readline())
for i in range(0,n):
numbers.append(int(s.readline()))
global NUMBERS
NUMBERS = numbers
return k
def check_if_number_present(value, depth, k):
global MIN_LENGTH
if depth > 8:
return
if value in NUMBERS:
if value in MIN_LENGTH:
if depth < MIN_LENGTH[value]:
MIN_LENGTH[value] = depth
else:
MIN_LENGTH[value] = depth
curr_k = k
curr_depth = depth+1
while(curr_depth <= 8):
check_if_number_present(value+curr_k,curr_depth,k)
if value!=0:
check_if_number_present(value-curr_k,curr_depth,k)
check_if_number_present(value*curr_k,curr_depth,k)
check_if_number_present(value/curr_k,curr_depth,k)
curr_k = curr_k*10+k
curr_depth = curr_depth+1
return
def print_min_monodig_values():
for each in NUMBERS:
if each in MIN_LENGTH:
print MIN_LENGTH[each]
else:
print "NO"
def solve():
s = sys.stdin
test_cases = int(s.readline())
for each in range(0,test_cases):
init()
k = read_input()
check_if_number_present(0,0,k)
print_min_monodig_values()
#if each!=test_cases-1:
#s.readline()
solve()