Search⌘ K
AI Features

Best Time to Buy and Sell Stock

Understand how to use greedy algorithms to maximize profit from stock trading by selecting the best days to buy and sell. This lesson helps you develop an O(n) time and O(1) space solution, improving your problem-solving skills for coding interviews.

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 ...