← Quiz: Kadane's Algorithm: all 13 questions
Quiz: Kadane's Algorithm · Question 11 of 13
What does this print? (code)
What does this print?
prices = [9, 4, 6, 2, 5, 3]
low, best = prices[0], 0
for p in prices[1:]:
best = max(best, p - low)
low = min(low, p)
print(best)
- A.2
- B.5
- C.7
- D.3
Answer & explanation
Correct answer: 3
Buy at 2, sell at 5 for a profit of 3. Selling at 9 is impossible because it comes before any lower price.
Can you get the rest right without peeking?
Take the timed Quiz: Kadane's Algorithm quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →