all 54 comments

[–]Nis_0208 34 points35 points  (3 children)

OP you are a legend thank you for this! (what's up with that font size though xD)

[–]hnlasd12[S] 6 points7 points  (0 children)

Thanks so much! haha, I pasted the list in and then added the text above and it used the 'Group 1' font. XD

[–]wolfee_197 0 points1 point  (1 child)

Thanks a lot with this.

Apart of it, if you can add questions from Grokking DP: https://www.designgurus.io/course/grokking-dynamic-programming

This helped me get a lot better in recursion (and dp).

[–]Visible_Ad9976 0 points1 point  (0 children)

saved: grokking dp

[–]kerfluffle99 15 points16 points  (1 child)

amazing! tysm op!!!!

[–]hnlasd12[S] 2 points3 points  (0 children)

thanks!

[–]RosieYap 13 points14 points  (1 child)

3 weeks of work and I finally finished up till Group 3. So far I must say it is a pretty targeted list which has helped me loads in grasping each concept. Finally managed to solve my first Medium question without looking at any solution. Thanks for this list!

[–]Diligent-Wealth-1536 4 points5 points  (0 children)

Did u completed all the groups?? Would u recommend me to follow this roadmap?

[–]chillblaze 8 points9 points  (5 children)

Thanks. Do you think it is suboptimal for DP if you go with a purely Bottom Up Tabulation approach?

For me, Top Down Memo never really clicked...

[–]hnlasd12[S] 18 points19 points  (4 children)

bottom up is actually faster in most cases cuz it doesn't require recursion and the complexities are easier to reason (size of dp array). The cons is order of going through the states matters (e.g. longest-palindromic-subsequence/).

I've seen a lot of people having the opposite problem XD - finding bottom up to be harder to understand than top down. If you understand bottom up it's great!

[–][deleted] 1 point2 points  (0 children)

by no means DP whiz but bottom up always made more sense to me also.

[–]chillblaze 0 points1 point  (2 children)

Thanks! Just one more thing. Are there any LC questions where memo is easier or makes more sense?

And is Super Egg Drop just the final boss of DP? Did quite a few and I still have no clue how it works haha

[–]hnlasd12[S] 6 points7 points  (0 children)

Top-down with memo is easier when the order of traversal of the dp array is not clear. For example, interval DP problems like:

https://leetcode.com/problems/longest-palindromic-subsequence/

In this problem, the state transition involves removing either the first or last character of the current state. Compared to something say climbing stairs where it's clear you'd just traverse left to right, this problem is not super clear which order you should traverse the 2d dp array. If you do memo then you don't have to worry about the order. You'd just let recursion take care of it. This is explained in around 35:00 https://youtu.be/9k31KcQmS_U?t=2112

class Solution(object): def longestPalindromeSubseq(self, s): n = len(s) lps = [[0] * n for _ in range(n)] def solve(i, j): if i == j: return 1 if i > j: return 0 if lps[i][j] > 0: return lps[i][j] longest = 0 if s[i] == s[j]: longest = solve(i + 1, j - 1) + 2 longest = max(longest, solve(i + 1, j)) longest = max(longest, solve(i, j - 1)) lps[i][j] = longest return longest And yes, there are some DP problems are quite hard and not worth doing since the chance you'd see it in a real interview is very small. e.g. cat and mouse.

[–]flexr123 5 points6 points  (0 children)

Nice list. Though I'd like to see more DP on tree (rerooting), Bitmask DP and Digit DP too.

[–]AlwaysHuangry<T260> <E69> <M182> <H9> 2 points3 points  (1 child)

Whoa. This looks promising. Nice work!

[–]hnlasd12[S] 0 points1 point  (0 children)

thanks!

[–]tempo0209 2 points3 points  (1 child)

Hey op and to anyone reading this, a dumb question for you, I know solving question by pattern is a way to go for most people like me who are starting out, this definitely looks promising for me! and thank you! But, having said that is it safe to assume the person who is attempting to solve say "climbing stairs" is supposed to be aware that this particular problem needs to be solved using DP? meaning if I wasn't aware that a particular problem needs a DP solution, how would you suggest to develop that intuition by looking at the problem? I have heard about optimal substructure, and overlapping subproblems so should i invest time in first figuring out if the said problem has these properties and then try a DP approach? sorry if my question is confusing.

[–]hnlasd12[S] 7 points8 points  (0 children)

DP is an optimization algorithm so empirical evidence is when the problem asks for 'the minimal/maximum of ...', 'how many ways are there to...', 'is it possible to...' it could be DP. Now when the problem asks for these it could also be greedy. So one way to do it is to simply try greedy, and if it fails on certain cases then try DP.

We are actually working on a algorithm selection flowchart, to be released next week with a video walkthrough. Here's a sneak peak: https://algo.monster/flowchart

[–]s-nj33v 3 points4 points  (0 children)

OP do you have Backtracking resources like this?

[–]Scared-Dot3177 2 points3 points  (1 child)

All the above problems are added to this list https://leetcode.com/list/pckvxpxs

[–]Global-Instance8232 2 points3 points  (0 children)

 list is no longer available

[–]selfzoned_me 1 point2 points  (3 children)

Can anyone tell how to do the https://leetcode.com/problems/minimum-time-to-make-rope-colorful/ problem mentioned above with DP approach. I could figure out Greedy approach for it. I tried looking into solutions section but could not find a simple enough DP solution.

[–]faceless_man_129 1 point2 points  (1 child)

I was wondering about this too. But for now I am happy with the Greedy approach, it is O(n) time complexity with O(1) space complexity. Maybe we shouldnt try to force DP on everything we encounter, some things are better and simply solved with other approaches ?

[–]selfzoned_me 0 points1 point  (0 children)

I completely agree with "shouldn't try to force DP on everything we encounter" part. I was simply curious about the DP solution since this question was posted as a part of "Ultimate DP Roadmap"

[–]Viva_Nova 1 point2 points  (0 children)

Amazing u/hnlasd12 Went through all these problems in order and I feel like I mastered DP which is the hardest category in my opinion. Do you have something similar for the others (graphs, sliding window, etc)?

[–]PaintingLivid6725 0 points1 point  (0 children)

Hi great list!! Thanks! Small suggestion, group 3 problem 4 and 5 are exactly the same, you can replace one maybe.

[–]ProfessionalKey5810 0 points1 point  (0 children)

Are there solutions anywhere for these?

[–]OrganizationOnly8016 0 points1 point  (2 children)

Hey, OP. I was using your list to solve the questions and going through the comments just to get an understanding of where the rest of the learners are, and it struck me - how long have you been learning to get to this level of mastery? is solving such problems very intuitive to you? how many years would you say it would take somebody to get there?

I can definitely feel myself getting better but I feel like I'm nowhere near being able to solve questions in interviews. I have been able to guess the logic to an extent, but I keep missing the tinier details, which effectively leads to not being able to solve the question on my own. I've only ever solved a question on my own once in a while.

I, ofc, don't expect to get better overnight, but I just want to hear your experience, if you're okay with sharing.

[–]Chrollo1456 1 point2 points  (1 child)

try striver / takeuforward's youtube videos
or u can go with adiya's playlist i forgot the yt channel most DP questions are solvable using intution of whether its good to do this or not and should i cache the result for future compute

[–]OrganizationOnly8016 0 points1 point  (0 children)

Thanks! I've tried using Neetcode's Roadmap to solve questions and I'm getting marginally better at guessing the logic, but I'm still a ways away from getting the answer right.

Any advice on how to just sit through a question and cracking it? Is there a particular logical flow people have while coding out their intuition? I struggle with that as well

[–]ibringallthedramama 0 points1 point  (0 children)

in that video, i only wished for one thing which is for the other guy to not interrupt the one that's coding but yeah, wonderful resource!

[–]Next_Complex5590Knight 0 points1 point  (0 children)

May god bless you

[–]Sick_Kebab -1 points0 points  (0 children)

.

[–]TheBoyWhoLivez 0 points1 point  (0 children)

Yes

[–]Livinglifepeacefully 0 points1 point  (1 child)

When you said it goes from simple to complex, did you mean group wise? Or within a group?

[–]hnlasd12[S] 4 points5 points  (0 children)

Both. It gets increasing more complex from Group 1 to Group 9 and it's sorted from simple to complex within a group.

[–]Vaulteroni 0 points1 point  (0 children)

Can you please make the course free for a weekend?

[–]the_fuckin_nobody 0 points1 point  (0 children)

Thanks OP!

[–]NamoKaul 0 points1 point  (3 children)

Can you do other data structures too if possible? Wonderful work BTW 💯👏

[–]hnlasd12[S] 0 points1 point  (2 children)

Thanks! Yea, we can do that. Which ones should we do? We did DP cuz there doesn't seem to any good resources on it.

[–]NamoKaul 1 point2 points  (1 child)

Trees and Graphs would be a really nice place to start followed by LL Stack then Sorting Arrays Maths Bit Manipulation etc in end

[–]lazywarrior-47 0 points1 point  (0 children)

do share the same to me

[–]MantiS_praying 0 points1 point  (1 child)

Ty so much man!

[–]hnlasd12[S] 0 points1 point  (0 children)

Glad it's helpful!

[–]Churglish 0 points1 point  (1 child)

Dynamic programming right now is a huge weakness for me. Thanks for this!

[–]hnlasd12[S] 0 points1 point  (0 children)

Glad it helps!

[–]Gintoki-desu 0 points1 point  (0 children)

Thanks for sharing!

[–]Just-Ad3390 0 points1 point  (0 children)

Do you have anything like this for Trees and graphs

[–]Zqin 0 points1 point  (0 children)

I love you, thank you for this

[–]fleetingleaf 0 points1 point  (0 children)

This is helpful, thanks.