Problems

3. Best Time to Buy and Sell Stock

EasyArrayAmazonMicrosoft

Given an array prices, return the maximum profit you can achieve from one buy and one sell.

Example 1:

Input: prices = [7,1,5,3,6,4]
Output: 5

Example 2:

Input: prices = [7,6,4,3,1]
Output: 0

Constraints:

  • 1 <= prices.length <= 10^5
Core code mode
● Auto-savedLine 1, column 1