filmov
tv
Best time to buy and sell stock with cooldown | Leetcode #309
Показать описание
This video explains the approach to solve the problem, best time to buy and sell stock with cooldown which is from leetcode 309.This is an extension for the problem best time to buy and sell stock 1 & 2.In this video,i have explained the approach to think about the solution for this problem and i have also shown how the given problem can be formulated as a recursion problem and how we can optimize it to solve the problem efficiently.In the second half of the video, i have explained the most efficient approach to solve this problem by making use of the states a person can be on a given day.There are only 3 states possible and so i have shown how the problem can be formulated into a state machine problem.This is the best approach which takes just O(N) time.This approach is also a dynamic programming approach.The space complexity can be reduced to O(1) because we just need to remember the previous day state a person can be.So, this can be done using 3 variables because we have just 3 possible states.At the end of the video, i have explained the code walkthrough of the given problem both by recursion + memoization and also state machine dynamic programming.CODE LINK is present below as usual. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
========================================================================
Join this channel to get access to perks:
=======================================================================
USEFUL LINK:-
========================================================================
Join this channel to get access to perks:
=======================================================================
USEFUL LINK:-
Комментарии