Easy55.4% acceptance

Best Time to Buy and Sell Stock

Find the maximum profit possible from buying and selling a stock.

Topics

ArraysGreedy

Examples

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

Expected Complexity

O(n) time and O(1) space.

What happens after Submit?

ERROR DNA analyzes your submission and identifies recurring patterns in your mistakes.

solution.cppC++17
Loading...
C++17