Best Time to Buy and Sell Stock
Last updated
What is Best Time to Buy and Sell Stock?
Given an array of daily stock prices, find the maximum profit from one buy and one sell. You track the minimum price seen so far and the best profit achievable at each step using a single pass. This is the simplest sliding window problem since the window always expands from the current day, and it teaches you how to track a running minimum and maximum simultaneously.
Free resources to learn Best Time to Buy and Sell Stock
More in stage 8: Sliding Window
Best Time to Buy and Sell Stock: common questions
Can I learn Best Time to Buy and Sell Stock in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Best Time to Buy and Sell Stock in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this Best Time to Buy and Sell Stock tutorial for beginners?
It is lesson 41 of 137 in the free LeetCode roadmap, in stage 8, Sliding Window. If you are new to LeetCode, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.