For prices = [7, 1, 5, 3, 6, 4], what is the best profit?
Practice this question from Best Time to Buy and Sell Stock - Greedy Pattern Practice Quiz, with options and an explanation.
Question
For prices = [7, 1, 5, 3, 6, 4], what is the best profit?
Option A
3
Option B
4
Option C — Correct answer
5
Option D
7
Explanation
Buy at 1 and sell at 6, giving profit 5.