Search⌘ K
AI Features

Best Time to Buy and Sell Stock

Explore greedy techniques to determine the best day to buy and sell stock to maximize profit. Understand constraints such as buying before selling and implement an optimal O(n) time, O(1) space solution. Practice problem-solving skills by rearranging logical steps and coding your solution.

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 future to sell it. ...