4th step sometimes not possible, but yeah up to 3 definitely.
I have been doing this with success 1. Identify states & understand state changes 2. Identify base case(s) 3. Identify recurrence relation 4. Top-down recursion + memoization 5. Bottom-up Tabulation 6. If possible, optimize space by removing a dimension in state
I'm just a tradesman and stumbled upon this vid. I have NO idea what's going on but it looks cool
very good summary of the step by step optimisation of DP problems, but it is hard for new learner to understand these 4 steps without a full blown explanation.
With these shorts, i should be able to become a code guru in one hour.
You could solve it in O(log(n)). Some say this problem could be solved in O(1), but they need to calculate the square root, and this costs O(log(n)).
I find that top-down solutions are easier to understand due to the decision tree nature of the solution as opposed to the bottom-up with dp that is sometimes harder to find the transition step.
Great video demonstrating progressive code refinement. Still not sure if the first step should be called "recursive backtracking". As discussed in previous video, think this is just "naïve recursion".
Nice breakdown! I've always found DP problems a bit tricky, but these steps make it sound way more manageable. Recursion to bottom-up with no memory is like leveling up each time! For those battling the usual coding interview prep grind, maybe mix it up with some real-world problems on zylyty too. They focus more on practical stuff which might save us from endless leetcode academic loops and you get to show off actual skills companies care about. Less AI cheating, more legit coding cred!
What do DP do?: It actually selects one best solution from all the possibilities And the possibilities are reduced by reusing/Memorization/Tabulation,(when there are 2 or more subproblems overlapping then we can avoid those subproblems and substitute from the memorization 😎)
What's complicated about DP IMO is figuring out what do the output depend on in such a way that it's memoizable, when facing new and complicated problems, It's not obvious at all
Just throw a HashMap on it
I think the memo dict would be a new one for each stack frame. I might be wrong. You are better off using lru_cache from functools or make the dict global
I thought I was good with Python until I saw this video
However: Tabulation (step 3) is not always faster than memoization (step 2) because the latter might avoid computing unnecessary table cells in some programming problems (not here, though).
Great tips! What would your tips for nailing down a ZYLYTY code challenge?
Hey Gregg, I'd love to see a deep dive into DP. Most importantly, I'd like to know how I can convert my naive approach progress from top-down to bottom-up to true dp solutions. Thanks in advance.
I am new to DS and I find this really beautiful ❤
🙏 bottom up approach saves me mostly
@GregHogg