Best Time to Buy and Sell Stock III Problem
Best Time to Buy and Sell Stock III Problem — ExecCode Hard DSA Practice
Solve the Best Time to Buy and Sell Stock III problem on ExecCode. Free online hard DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
You are given an array prices where prices[i] is the price of a given stock on the ith day. Find the maximum profit you can achieve. You may complete at most two transactions. You may not hold more than one share at a time.
Examples
Input prices = [1, 2, 3, 0, 2]; Output 4. Input prices = [3, 3, 5, 0, 0, 3, 1, 4]; Output 6. Input prices = [1, 2, 3, 4, 5]; Output 4
Constraints
1 ≤ prices.length ≤ 10⁵ 0 ≤ prices[i] ≤ 10⁵
Practice Best Time to Buy and Sell Stock III free on ExecCode. Browse DSA problems, topic map, and placement guides.