Best Time to Buy and Sell Stock II Problem

Best Time to Buy and Sell Stock II Problem — ExecCode Medium DSA Practice

Solve the Best Time to Buy and Sell Stock II problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

You may complete as many transactions as you like (buy then sell), but may hold at most one stock at a time. Return the maximum profit.

Examples

Input prices = [7, 1, 5, 3, 6, 4]; Output 7

Constraints

1 ≤ prices.length ≤ 3·10^4 0 ≤ prices[i] ≤ 10^4

Practice Best Time to Buy and Sell Stock II free on ExecCode. Browse DSA problems, topic map, and placement guides.