Coding Challenge

Best Time to Buy and Sell Stock

Easy
arraysliding-window

Find the maximum profit from one buy and one sell.

Given daily stock prices, choose one day to buy and a later day to sell. Return the maximum profit you can achieve, or 0 if no profit is possible.

Examples

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

Output: 5

Constraints

  • 1 <= prices.length

Preparing your coding workspace...