Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Best Time to Buy and Sell Stock

XPChallenge Points: 10
levelLevel: Easy

You are given an array prices where prices[i] represents the price of a stock on the i-th day.
Your goal is to find the maximum profit you can achieve by choosing one day to buy the stock and a different day in the future to sell it.
If no profit can be made (i.e., prices keep decreasing), return 0.

Example 1:

Input: prices = [8, 3, 6, 1, 9, 5]

Output: 8

Example 2:

Input: prices = [10, 9, 8, 7, 6]

Output: 0

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result