Best Time to Buy and Sell Stock
EasyGiven an array prices where prices[i] is the price of a given stock on day i, find the maximum profit you can achieve. You may only complete one transaction (i.e., buy one and sell one share of the stock).
Example:
Input: prices = [7,1,5,3,6,4] Output: 5 Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
Test Cases
Test Cases
Input
7 1 5 3 6 4
Expected Output
5
Step 1
Step 2
Step 3
Step 4
Step 1: Identify the Pattern
Best Time to Buy and Sell Stock
EasyGiven an array prices where prices[i] is the price of a given stock on day i, find the maximum profit you can achieve. You may only complete one transaction (i.e., buy one and sell one share of the stock).
Example:
Input: prices = [7,1,5,3,6,4] Output: 5 Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
Test Cases
Test Cases
Input
7 1 5 3 6 4
Expected Output
5
Step 1
Step 2
Step 3
Step 4
Step 1: Identify the Pattern
Study Notes
Start Taking Notes!
Create and organize your study notes for this problem. Keep track of your solutions and insights.