45. DP on stocks
these are just knapsack variations
---------------------------------------------------------------------------------------------------------------
DP on stocks-1:
(1 transaction)
Ques- we want to find max profit we can make by buying on i-th day and selling of a day > i
Soln- iterating from start to end , see profit for each guy as curr - min(from start to prev index )
DP on stocks-2:
(Infinite transactions)
e.g., 715364: (1-5, 3-6) => (4+3=7)
Approach-1: greedy
---------------------------------------------------------------------------------------------------------------
DP on stocks-3:
(max 2 transactions)
DP on stocks-4:
(max K transactions)
simple- upar wale code mein 2 ki jagah k daaldo
---------------------------------------------------------------------------------------------------------------
DP on stocks-5:
(cooldown of 1 day after a sell- BScBScBS... & infinite transactions)
simple- infinite transactions ke code mein sell krne wali condition mein i+1 ki jagah i+2 krde
PS- yaha space optimisation mein prev1 aur prev2 lagenge aur tabulation mein n+2 tak krna padega
---------------------------------------------------------------------------------------------------------------
DP on stocks-6:
(with transaction fee + infinite transactions)
simple: sell wale mein agar sell kar rhe ho toh ( - fee ) bhi kardo
--------------------------------------------------------------------------------------------------------------






Comments
Post a Comment