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
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.