Skip to content

Commit aa2989d

Browse files
author
Philip Guo
committed
added another problem
1 parent a314b9f commit aa2989d

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

‎questions/two-sum.txt‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Name:
2+
Two-Sum
3+
4+
Question:
5+
Write a function to return the sum of the two largest elements in the
6+
given list.
7+
8+
Hint:
9+
Think about sorting.
10+
11+
Solution:
12+
Sort the list and extract out the two largest elements, then return
13+
their sum.
14+
15+
Skeleton:
16+
17+
def sumTwoLargest(lst):
18+
# write your solution code here
19+
20+
Test:
21+
input = [5,3,4,7,10]
22+
result = sumTwoLargest(input)
23+
24+
Expect:
25+
result = 17
26+
27+
Test:
28+
input = [5,4,3,2,1]
29+
result = sumTwoLargest(input)
30+
31+
Expect:
32+
result = 9
33+
34+
Test:
35+
input = [3,7]
36+
result = sumTwoLargest(input)
37+
38+
Expect:
39+
result = 10
40+
41+
Test:
42+
input = [1,1,1,1,1,1,1,1,1,1]
43+
result = sumTwoLargest(input)
44+
45+
Expect:
46+
result = 2
47+
48+
Test:
49+
input = [1,9,5,7,3]
50+
result = sumTwoLargest(input)
51+
52+
Expect:
53+
result = 16
54+

0 commit comments

Comments
 (0)