Best Time to Buy and Sell Stock
Easy
Arrays
Array
Dynamic Programming
Given array of stock prices, find max profit from one buy and one sell. Print 0 if no profit.
Constraints
1 ≤ prices.length ≤ 10^5
Examples
Example 1:
Input: 7 1 5 3 6 4
Output: 5
Explanation: Buy at 1, sell at 6
Example 2:
Input: 7 6 4 3 1
Output: 0
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console