9. Best Time to Buy and Sell Stock#121
Easy👁 Sliding WindowTrack Minimum
Find the maximum profit from buying and selling a stock once, given daily prices.
Examples
Example 1:
Input: [[7,1,5,3,6,4]]
Output: 5
Example 2:
Input: [[7,6,4,3,1]]
Output: 0
Example 3:
Input: [[2,4,1]]
Output: 2
Why learn this
Teaches tracking min-so-far while scanning — a foundational greedy/sliding window pattern.
ArraysSliding WindowGreedy
Python 3Loading Python engine...
Click "Run Code" to test your solution