Locked
Pass the Dictionary check first
Everything after it builds on dictionaries. Each rep in the check has to be passed without opening the solution. Hints and Basics are fine.
Still to clear · 8 of 8
- Trace: keep the table
- Which line crashes?
- Write: menu from two lists
- Write: total a bill
- Debug: cheapest item
- Write: items under a budget
- Write: who sits where
- Write: apply price changes
Preview · where this ladder is heading
Best Time to Buy and Sell Stock
prices[i] is a share's price on day i. The list may be empty. You may buy once and sell once. The sale must be on a later day than the purchase. Return the largest profit you could make. If no trade makes money, return 0.
One pass, O(1) extra space.
max_profit([7, 1, 5, 3, 6, 4]) → 5 (buy at 1, sell at 6) max_profit([7, 6, 4, 3, 1]) → 0 (prices only go down)
inprices = [7, 1, 5, 3, 6, 4]out5
inprices = [7, 6, 4, 3, 1]out0
You can read it now. The editor opens when the check is cleared.