Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d287e7b

Browse files
author
Philip Guo
committed
bah
1 parent 917c7c5 commit d287e7b

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

question.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060

6161
<div id="questionsHeaderPane">
6262

63-
<div class="questionsHeaderTitle" id="ProblemName"></div>
63+
<div class="questionsHeaderTitle" id="ProblemName">Please load a question ...</div>
6464

65-
<div class="questionsHeaderStmt" id="ProblemStatement"><b>(Please load a question, e.g., "?inplace-reverse")</b></div>
65+
<div class="questionsHeaderStmt" id="ProblemStatement"></div>
6666

6767
<div class="questionsHeaderStmt" id="HintStatement"><a href="#" id="showHintHref">Show hint</a></div>
6868
<div class="questionsHeaderStmt" id="SolutionStatement"><a href="#" id="showSolutionHref">Show solution</a></div>

questions/debug-mergesort.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Debug: Mergesort
33

44
Question:
55

6-
Add at most TWO lines of code to make the given mergesort function work
7-
properly.
6+
Add at most TWO lines of code to make the given broken mergesort
7+
function work properly.
88

99
Hint:
1010
Focus on the merge function.

questions/optimize-search.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Name:
2-
Optimize: Element search
2+
Optimize: List search
33

44
Question:
55

questions/optimize-sum.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Name:
2+
Optimize: Greatest sum
3+
4+
Question:
5+
6+
The given function finds the greatest sum amongst all pairs of elements
7+
in the array. Optimize this function so that it works on any 5-element
8+
list list by executing less than 20 instructions.
9+
10+
Hint:
11+
Think about sorting.
12+
13+
Solution:
14+
Sort the list and return the sum of the two largest elements.
15+
16+
MaxInstructions: 20
17+
18+
Skeleton:
19+
20+
def maxPairSum(lst):
21+
maxSum = None
22+
for i in range(len(lst)):
23+
for j in range(i + 1, len(lst)):
24+
maxSum = max(lst[i] + lst[j], maxSum)
25+
return maxSum
26+
27+
28+
Test:
29+
input = [10, 2, 1, 7, 3, 4, 5, 6, 8, 9]
30+
result = maxPairSum(input)
31+
32+
Expect:
33+
result = 19
34+
35+
Test:
36+
input = [10, 2, 1, 7, 3, 4, 5, 6, 80, 9]
37+
result = maxPairSum(input)
38+
39+
Expect:
40+
result = 90
41+
42+
Test:
43+
input = [1,1,1,1,2,1,1,1,1,1]
44+
result = maxPairSum(input)
45+
46+
Expect:
47+
result = 3
48+

0 commit comments

Comments
 (0)