본문 바로가기
Problem Solving/Codility

[Python] 6.2. MaxProductOfThree

by 부르르 2021. 3. 25.

https://app.codility.com/programmers/lessons/6-sorting/

 

6. Sorting lesson - Learn to Code - Codility

Maximize A[P] * A[Q] * A[R] for any triplet (P, Q, R).

app.codility.com


Task Score

100%

Correctness

100%

Performance

100%

Detected time complexity

O(N * log(N))

def solution(A):
    
    _A = sorted(A)
    
    return max(_A[0]*_A[1]*_A[-1], _A[-3]*_A[-2]*_A[-1])

 

 

728x90
반응형

'Problem Solving > Codility' 카테고리의 다른 글

[Python] 6.4. Triangle  (0) 2021.03.26
[Python] 6.3. NumberOfDiscIntersections  (0) 2021.03.25
[Python] 6.1. Distinct  (0) 2021.03.25
[Python] 5.4. PassingCars  (0) 2021.03.24
[Python] 5.3. MinAvgTwoSlice  (0) 2021.03.18

댓글