Tasks Details
easy
Maximize A[P] * A[Q] * A[R] for any triplet (P, Q, R).
Task Score
88%
Correctness
75%
Performance
100%
A non-empty array A consisting of N integers is given. The product of triplet (P, Q, R) equates to A[P] * A[Q] * A[R] (0 ≤ P < Q < R < N).
For example, array A such that:
A[0] = -3 A[1] = 1 A[2] = 2 A[3] = -2 A[4] = 5 A[5] = 6contains the following example triplets:
- (0, 1, 2), product is −3 * 1 * 2 = −6
- (1, 2, 4), product is 1 * 2 * 5 = 10
- (2, 4, 5), product is 2 * 5 * 6 = 60
Your goal is to find the maximal product of any triplet.
Write a function:
def solution(A)
that, given a non-empty array A, returns the value of the maximal product of any triplet.
For example, given array A such that:
A[0] = -3 A[1] = 1 A[2] = 2 A[3] = -2 A[4] = 5 A[5] = 6the function should return 60, as the product of triplet (2, 4, 5) is maximal.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [3..100,000];
- each element of array A is an integer within the range [−1,000..1,000].
Copyright 2009–2025 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used Python
Time spent on task 80 minutes
Notes
not defined yet
Code: 04:44:17 UTC,
java,
autosave
Code: 04:53:49 UTC,
py,
verify,
result: Failed
Analysis
expand all
Example tests
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
[1, 2, -2, -3, 5, 6]
Code: 04:55:37 UTC,
py,
verify,
result: Failed
Analysis
expand all
Example tests
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
6 5 -3 2 -2 1
Code: 04:58:45 UTC,
py,
verify,
result: Failed
Analysis
expand all
Example tests
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
0 6 1 5 2 -3 3 2 4 -2 5 1
Code: 04:59:10 UTC,
py,
autosave
Code: 05:09:26 UTC,
py,
autosave
Code: 05:09:56 UTC,
py,
autosave
Code: 05:10:07 UTC,
py,
autosave
Code: 05:11:51 UTC,
py,
autosave
Code: 05:12:06 UTC,
py,
autosave
Code: 05:16:00 UTC,
py,
autosave
Code: 05:25:25 UTC,
py,
autosave
Code: 05:25:39 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A, key = abs, reverse = True)
count, keep_num = 0, 0
for i, num in enumerate(sorted_A):
if num < 0:
Code: 05:29:36 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A, key = abs, reverse = True)
count, keep_num = 0, 0
for i, num in enumerate(sorted_A):
if num < 0:
Code: 05:29:53 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A, key = abs, reverse = True)
count, keep_num = 0, 0
for i, num in enumerate(sorted_A):
if num < 0:
else:
count+=1
Code: 05:30:04 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A, key = abs, reverse = True)
answer, count, keep_num = 0, 0
for i, num in enumerate(sorted_A):
if num < 0:
else:
count+=1
Code: 05:30:16 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A, key = abs, reverse = True)
answer, count, keep_num = 1, 0, 0
for i, num in enumerate(sorted_A):
if num < 0:
else:
answer *=
count+=1
Code: 05:30:27 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A, key = abs, reverse = True)
answer, count, keep_num = 1, 0, 0
for i, num in enumerate(sorted_A):
if num < 0:
else:
answer *= num
count+=1
Code: 05:33:29 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A, key = abs, reverse = True)
answer, count, keep_num = 1, 0, 0
for i, num in enumerate(sorted_A):
if num < 0:
else:
answer *= num
count+=1
Code: 05:33:52 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A, key = abs, reverse = True)
answer, count, keep_num = 1, 0, 0
for i, num in enumerate(sorted_A):
if count == 3:
return answer
if num < 0:
keep_num == num
else:
answer *= num
count+=1
Code: 05:34:14 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A, key = abs, reverse = True)
answer, count, keep_num = 1, 0, 0
for i, num in enumerate(sorted_A):
if count == 3:
return answer
if num < 0:
keep_num == num
else:
answer *= num
count+=1
Code: 05:40:14 UTC,
py,
autosave
Code: 05:40:29 UTC,
py,
autosave
Code: 05:40:59 UTC,
py,
autosave
Code: 05:43:18 UTC,
py,
verify,
result: Failed
Analysis
expand all
Example tests
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Invalid result type, int expected, <class 'NoneType'> found.stdout:
[-3, -2, 1, 2, 5, 6]
Code: 05:44:10 UTC,
py,
autosave
Code: 05:44:31 UTC,
py,
autosave
Code: 05:44:43 UTC,
py,
autosave
Code: 05:45:13 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
need_to_multiply = max(minus_num_multiply , sorte)
Code: 05:45:30 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
need_to_multiply = max(minus_num_multiply , sorted_A[i-1] * sorted_A[i-2])
Code: 05:45:51 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
need_to_multiply = max(minus_num_multiply , sorted_A[i-1] * sorted_A[i-2])
Code: 05:46:24 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
need_to_multiply = max(minus_num_multiply , sorted_A[i-1] * sorted_A[i-2])
Code: 05:46:55 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
need_to_multiply = max(minus_num_multiply , sorted_A[i-1] * sorted_A[i-2])
answer = minus_num_multiply[i] * need_to_multiply
Code: 05:47:06 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
need_to_multiply = max(minus_num_multiply , sorted_A[i-1] * sorted_A[i-2])
answer = minus_num_multiply[i] * need_to_multiply
return answer
Code: 05:47:33 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
need_to_multiply = max(minus_num_multiply , sorted_A[length_A-2] * sorted_A[length_A-1])
answer = minus_num_multiply[length_A] * need_to_multiply
return answer
Code: 05:47:38 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
need_to_multiply = max(minus_num_multiply , sorted_A[length_A-2] * sorted_A[length_A-1])
answer = minus_num_multiply[length_A] * need_to_multiply
return answer
Analysis
expand all
Example tests
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Traceback (most recent call last): File "exec.py", line 129, in <module> main() File "exec.py", line 91, in main result = solution( A ) File "/tmp/solution.py", line 17, in solution answer = minus_num_multiply[length_A] * need_to_multiply TypeError: 'int' object is not subscriptablestdout:
[-3, -2, 1, 2, 5, 6]
Code: 05:50:52 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
answer = minus_num_multiply[length_A] * need_to_multiply
return answer
Code: 05:51:04 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(minus_num_multiply)
answer = minus_num_multiply[length_A] * need_to_multiply
return answer
Code: 05:51:08 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(minus_num_multiply)
return answer
Analysis
expand all
Example tests
1.
0.040 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Traceback (most recent call last): File "exec.py", line 129, in <module> main() File "exec.py", line 91, in main result = solution( A ) File "/tmp/solution.py", line 18, in solution return answer NameError: name 'answer' is not definedstdout:
[-3, -2, 1, 2, 5, 6] 6
Code: 05:51:18 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(minus_num_multiply)
return answer
Code: 05:51:43 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(minus_num_multiply)
need_to_multiply = max(minus_num_multiply, )
return answer
Code: 05:52:08 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(minus_num_multiply)
print(sorted[length_A - 1])
#need_to_multiply = max(minus_num_multiply, )
return answer
Code: 05:52:08 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(minus_num_multiply)
print(sorted[length_A - 1])
#need_to_multiply = max(minus_num_multiply, )
return answer
Analysis
expand all
Example tests
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Traceback (most recent call last): File "exec.py", line 129, in <module> main() File "exec.py", line 91, in main result = solution( A ) File "/tmp/solution.py", line 18, in solution print(sorted[length_A - 1]) TypeError: 'builtin_function_or_method' object is not subscriptablestdout:
[-3, -2, 1, 2, 5, 6] 6
Code: 05:52:19 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(minus_num_multiply)
print(sorted[length_A - 3] * )
#need_to_multiply = max(minus_num_multiply, )
return answer
Code: 05:52:24 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(minus_num_multiply)
print(sorted_A[length_A - 3] * )
#need_to_multiply = max(minus_num_multiply, )
return answer
Analysis
expand all
Example tests
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Traceback (most recent call last): File "exec.py", line 129, in <module> main() File "exec.py", line 70, in main sol = __import__('solution') File "/tmp/solution.py", line 18 print(sorted_A[length_A - 3] * ) ^ SyntaxError: invalid syntax
Code: 05:52:37 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(minus_num_multiply)
print(sorted_A[length_A - 3] )
#need_to_multiply = max(minus_num_multiply, )
return answer
Analysis
expand all
Example tests
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Traceback (most recent call last): File "exec.py", line 129, in <module> main() File "exec.py", line 91, in main result = solution( A ) File "/tmp/solution.py", line 22, in solution return answer NameError: name 'answer' is not definedstdout:
[-3, -2, 1, 2, 5, 6] 6 2
Code: 05:52:49 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(minus_num_multiply)
print(sorted_A[length_A - 3] * sorted_A[length] )
#need_to_multiply = max(minus_num_multiply, )
return answer
Code: 05:53:00 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(minus_num_multiply)
print(sorted_A[length_A - 3] * sorted_A[length_A - 2])
#need_to_multiply = max(minus_num_multiply, )
return answer
Code: 05:53:03 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(minus_num_multiply)
print(sorted_A[length_A - 3] * sorted_A[length_A - 2])
#need_to_multiply = max(minus_num_multiply, )
return answer
Analysis
expand all
Example tests
1.
0.040 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Traceback (most recent call last): File "exec.py", line 129, in <module> main() File "exec.py", line 91, in main result = solution( A ) File "/tmp/solution.py", line 22, in solution return answer NameError: name 'answer' is not definedstdout:
[-3, -2, 1, 2, 5, 6] 6 10
Code: 05:53:17 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(minus_num_multiply)
print(sorted_A[length_A - 3] * sorted_A[length_A - 2])
#need_to_multiply = max(minus_num_multiply, )
answer =
return answer
Code: 05:54:08 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(minus_num_multiply)
print(sorted_A[length_A - 3] * sorted_A[length_A - 2])
#need_to_multiply = max(minus_num_multiply, )
answer =
return answer
Code: 05:54:24 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
if sorted_A[length_A -1]:
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(minus_num_multiply)
print(sorted_A[length_A - 3] * sorted_A[length_A - 2])
#need_to_multiply = max(minus_num_multiply, )
answer =
return answer
Code: 05:56:49 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
if sorted_A[length_A -1]:
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(sorted_A[length_A - 3] * sorted_A[length_A - 2])
#need_to_multiply = max(minus_num_multiply, )
answer =
return answer
Code: 05:57:04 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
if sorted_A[length_A -1] > 0:
minus_num_multiply = sorted_A[0] * sorted_A[1]
print(sorted_A[length_A - 3] * sorted_A[length_A - 2])
#need_to_multiply = max(minus_num_multiply, )
answer =
return answer
Code: 05:58:53 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
if sorted_A[length_A -1] > 0:
minus_num_multiply = sorted_A[0] * sorted_A[1]
psorted_A[length_A - 3] * sorted_A[length_A - 2])
#need_to_multiply = max(minus_num_multiply, )
answer =
return answer
Code: 05:59:23 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
if sorted_A[length_A -1] > 0:
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
#need_to_multiply = max(minus_num_multiply, )
answer =
return answer
Code: 05:59:35 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
answer = if
return answer
Code: 05:59:45 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
answer = if sorted
return answer
Code: 06:00:01 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
answer = if sorted_A[length_A - 1] > 0
return answer
Code: 06:00:32 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
last_num = sorted_A[length_A-1]
print()
return answer
Code: 06:00:48 UTC,
py,
verify,
result: Failed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
last_num = sorted_A[length_A-1]
print(min_num_multiply, max_num_multiply, last_num)
return answer
Analysis
expand all
Example tests
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Traceback (most recent call last): File "exec.py", line 129, in <module> main() File "exec.py", line 91, in main result = solution( A ) File "/tmp/solution.py", line 22, in solution return answer NameError: name 'answer' is not definedstdout:
[-3, -2, 1, 2, 5, 6] 6 10 6
Code: 06:01:02 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
last_num = sorted_A[length_A-1]
print(min_num_multiply, max_num_multiply, last_num)
answer = last_num
return answer
Code: 06:01:13 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
last_num = sorted_A[length_A-1]
print(min_num_multiply, max_num_multiply, last_num)
answer = last_num * max(min)
return answer
Code: 06:02:01 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
last_num = sorted_A[length_A-1]
print(min_num_multiply, max_num_multiply, last_num)
answer = last_num * max(min_num_multiply)
return answer
Code: 06:02:28 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
print(sorted_A)
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
last_num = sorted_A[length_A-1]
print(min_num_multiply, max_num_multiply, last_num)
answer = last_num * max(min_num_multiply, max_num_multiply) else last_num* min(min_num_multiply, )
return answer
Code: 06:02:44 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
#print(sorted_A)
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
last_num = sorted_A[length_A-1]
#print(min_num_multiply, max_num_multiply, last_num)
answer = last_num * max(min_num_multiply, max_num_multiply) else last_num* min(min_num_multiply, max_num_multiply)
return answer
Code: 06:02:55 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
#print(sorted_A)
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
last_num = sorted_A[length_A-1]
#print(min_num_multiply, max_num_multiply, last_num)
answer = last_num * max(min_num_multiply, max_num_multiply) else last_num * min(min_num_multiply, max_num_multiply)
return answer
Code: 06:03:09 UTC,
py,
autosave
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
#print(sorted_A)
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
last_num = sorted_A[length_A-1]
#print(min_num_multiply, max_num_multiply, last_num)
answer = last_num * max(min_num_multiply, max_num_multiply) if last_num >= 0 else last_num * min(min_num_multiply, max_num_multiply)
return answer
Code: 06:03:12 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
#print(sorted_A)
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
last_num = sorted_A[length_A-1]
#print(min_num_multiply, max_num_multiply, last_num)
answer = last_num * max(min_num_multiply, max_num_multiply) if last_num >= 0 else last_num * min(min_num_multiply, max_num_multiply)
return answer
Analysis
Code: 06:03:19 UTC,
py,
verify,
result: Passed
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
#print(sorted_A)
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
last_num = sorted_A[length_A-1]
#print(min_num_multiply, max_num_multiply, last_num)
answer = last_num * max(min_num_multiply, max_num_multiply) if last_num >= 0 else last_num * min(min_num_multiply, max_num_multiply)
return answer
Analysis
Code: 06:03:21 UTC,
py,
final,
score: 
88
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import math
def solution(A):
length_A = len(A)
if length_A== 3:
return math.prod(A)
sorted_A = sorted(A)
#print(sorted_A)
min_num_multiply = sorted_A[0] * sorted_A[1]
max_num_multiply = sorted_A[length_A - 3] * sorted_A[length_A - 2]
last_num = sorted_A[length_A-1]
#print(min_num_multiply, max_num_multiply, last_num)
answer = last_num * max(min_num_multiply, max_num_multiply) if last_num >= 0 else last_num * min(min_num_multiply, max_num_multiply)
return answer
Analysis summary
The following issues have been detected: runtime errors.
For example, for the input [10, 10, 10] the solution terminated unexpectedly.
Analysis
Detected time complexity:
O(N * log(N))
expand all
Correctness tests
1.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Traceback (most recent call last): File "exec.py", line 129, in <module> main() File "exec.py", line 91, in main result = solution( A ) File "/tmp/solution.py", line 9, in solution return math.prod(A) AttributeError: module 'math' has no attribute 'prod'
2.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Traceback (most recent call last): File "exec.py", line 129, in <module> main() File "exec.py", line 91, in main result = solution( A ) File "/tmp/solution.py", line 9, in solution return math.prod(A) AttributeError: module 'math' has no attribute 'prod'
3.
0.036 s
RUNTIME ERROR,
tested program terminated with exit code 1
stderr:
Traceback (most recent call last): File "exec.py", line 129, in <module> main() File "exec.py", line 91, in main result = solution( A ) File "/tmp/solution.py", line 9, in solution return math.prod(A) AttributeError: module 'math' has no attribute 'prod'
1.
0.036 s
OK
2.
0.036 s
OK
3.
0.036 s
OK
4.
0.036 s
OK
1.
0.036 s
OK
2.
0.036 s
OK
3.
0.036 s
OK
1.
0.036 s
OK
expand all
Performance tests
1.
0.040 s
OK
1.
0.048 s
OK
1.
0.176 s
OK
1.
0.088 s
OK
1.
0.124 s
OK
2.
0.140 s
OK