what is wrong with the code it is not passing all testcases
question–>
code–>
Best time to buy and sell 3
Hey @sheikhhaji18
On;y 5% testases are running
so that means your logic is Incorrect and not considering many cases
[1,2,3,4,5] is one of them
My suggestion is u should refer to Solution Editorial of the problem :https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/discuss/937778/C%2B%2B-oror-Full-Explained-Code-oror-Video-oror-O(N)
its passing 168/214 test cases
Okay ,please explain ur algo briefly
see i am considering two cases–>
1)when the price is zero any day ->
then
–>consider two cases
a)buying stocks from the starting and selling
else{
b) not buying stocks till i see zero in my array
}
2) when there is no zero in the array i will just use the approach ofbest time buy and sell two approach
You are not able to keep track of max tranactions ==2
See for this [1,5,2,1,5,2,1,5]
Ur output =12
expected =8
U are nowhere considering the fact that maximum transaction u can do is 2
i am just considering the profit not transaction okay my approach not working i will the editoral video
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.