Best Time to Buy and Sell Stock |

I came across these two questions and found similarities.

  1. Buy and Sell only 1 time to get maximum profit.
  2. Buy and Sell multiple times to get maximum profit.

Here comes the solutions for the same, The code is the same for both the questions but with minor differences.

Solution 1: Buy and Sell single time:

Solution 2: Buy and Sell Multiple times:

Happy Coding!

Software Developer