Please elaborate the question with its testcase example
Question not understood
The question says buy -sell - repeat.
You can hold atmost 1 share at a time. That means, once you buy a stock , you must sell it to be able to buy another one.
Given test case:
You have 23 4 5 9 20
So best choice is you buy at price 4 and then sell at price 20 to get max profit 16.
other possible : buy at 4 sell at 5, buy at 9 sell at 20 to get profit 12.
NOTE: buy at 4, buy at 5 and sell them at 9 and 12 is not possible. You must sell before buying second one.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.