Best Time to Buy Sell Stock II Problem
Best Time to Buy Sell Stock II Problem — ExecCode Easy DSA Practice
Solve the Best Time to Buy Sell Stock II problem on ExecCode. Free online easy DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given an integer array prices where prices[i] is the price of a given stock on the i^th day. Your task is to find and return the maximum profit you can achieve. On each day, you may decide to buy and/or sell the stock. You can only hold at most one share of the stock at any time. However, you can sell and buy the stock multiple times on the same day, ensuring you never hold more than one share of the stock.
Examples
Input {"nums": [7, 1, 5, 3, 6, 4]}; Output 7. Input {"nums": [1, 2, 3, 4, 5]}; Output 4. Input {"nums": [7, 6, 4, 3, 1]}; Output 0
Constraints
1 <= prices.length <= 3 * 10^4 0 <= prices[i] <= 10^4
Practice Best Time to Buy Sell Stock II free on ExecCode. Browse DSA problems, topic map, and placement guides.