Skip to content

Latest commit

 

History

History
12 lines (9 loc) · 636 Bytes

File metadata and controls

12 lines (9 loc) · 636 Bytes

Problem 16: The Stock Trader (Best Time to Buy and Sell Stock with Cooldown)

Problem Statement

You are given an array prices where prices[i] is the price of a given stock on the i-th day. Find the maximum profit you can achieve. You may complete as many transactions as you like with the following restrictions: After you sell your stock, you cannot buy stock on the next day (i.e., cooldown one day).

Input Format

  • An array of integers prices.

Example

Input: prices = [1, 2, 3, 0, 2]
Output: 3
Explanation: Buy on day 0, sell on day 2 (profit=2). Buy on day 3, sell on day 4 (profit=2). Total = 3.