Easy · Arrays
Max profit selling stocks
Given an array prices where prices[i] is a stock's price on day i, return the maximum profit from buying on one day and selling on a later day, or 0 if no trade makes a profit.
Examples
Example 1
[7,1,5,3,6,4]Output: max profit 5
Example 2
[7,6,4,3,1]Output: max profit 0
Rebuild it in the studio
Open every published interview problem, solution, scene, and memory room free, with no account.