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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store