Search⌘ K
AI Features

Best Time to Buy and Sell Stock

Explore how to apply greedy algorithms to solve the problem of maximizing stock trading profit by choosing the optimal day to buy and a later day to sell. Understand the constraints and practice developing an efficient O(n) time solution with minimal space that ensures no selling before buying.

Statement

Given an array, prices, where prices[i] represent the price of a stock on the i-th day, maximize profit by selecting a single day to buy the stock and a different day in the ...