나는 이렇게 학습한다/Algorithm & SQL

0917. Largest pair sum in array

daco2020 2022. 9. 17. 21:56
반응형

Given a sequence of numbers, find the largest pair sum in the sequence.

For example

[10, 14, 2, 23, 19] -->  42 (= 23 + 19)
[99, 2, 2, 23, 19]  --> 122 (= 99 + 23)

Input sequence contains minimum two elements and every element is an integer.



Solution:

def largest_pair_sum(numbers): 
    return sum(sorted(numbers)[-2:])


반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

0919. Cat years, Dog years  (0) 2022.09.19
0918. Grasshopper - Array Mean  (0) 2022.09.19
0916. Do you speak "English"?  (0) 2022.09.16
0915. Beginner - Reduce but Grow  (0) 2022.09.15
0914. Rock Paper Scissors!  (0) 2022.09.14