Leetcode: Best Time to Buy and Sell Stock II

How to Solve the Problem and the Concepts Behind It

Photo by Clément Hélardot on Unsplash

Leetcode defines the problem as follows:

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 as many transactions as you like (i.e., buy one and sell one…