def solution(xs): # Set initial values (ignore any leading zeros) startPoint = next((index for index, value in enumerate(xs) if value != 0), None) maxCap = xs[startPoint] smallestNegative = -9223372036854775808 # Largest Negative Starting Value # Test edge case of just one item in the array try: xs[startPoint+1] except IndexError: return str(xs[0]) # One time check to see if maxCap contains a negative value if maxCap > smallestNegative and maxCap < 0: smallestNegative = maxCap # Loop through the rest of array for item in xs[startPoint+1:]: if item > smallestNegative and item < 0: smallestNegative = item if item != 0: maxCap *= item # If the value ends on negative - undo the smallest multipication for the biggest number if maxCap < 0: maxCap /= smallestNegative return str(maxCap) case1 = int(solution([0,0,0,0,2,0,2,2,0])) # 8 # case2 = int(solution([0,-2,-3,4,-5])) # 60 if case1 == 8: print "Test 1: Passed" else: print "Test 1: Failed" print "Recieved " + str(case1) # if case2 == 60: # print "Test 2: Passed" # else: # print "Test 2: Failed" # print "Recieved " + str(case2)