Learn how to use Dynamic Programming in this course for beginners. It can help you solve complex programming problems, such as those often seen in programming interview questions about data structures and algorithms.

This course was developed by Alvin Zablan from Coderbyte. Coderbyte is one of the top websites for technical interview prep and coding challenges.

🔗 Check out the Coderbyte channel:

🔗 Improve your coding and interview skills: (NOT an affiliate link)

This course uses images and animations to help you visualize problems and important concepts. After understanding problems conceptually, you will learn how to solve them in JavaScript using Dynamic Programming. Even though JavaScript is used in this course, you will learn concepts and knowledge that you can apply to other programming languages.

⭐️ Course Contents ⭐️

⌨️ (00:00:00) course introduction

⌨️ (00:03:30) fib memoization

⌨️ (00:38:39) gridTraveler memoization

⌨️ (01:04:52) memoization recipe

⌨️ (01:09:56) canSum memoization

⌨️ (01:29:29) howSum memoization

⌨️ (01:52:06) bestSum memoization

⌨️ (02:12:45) canConstruct memoization

⌨️ (02:38:36) countConstruct memoization

⌨️ (02:47:30) allConstruct memoization

⌨️ (03:10:53) fib tabulation

⌨️ (03:22:17) gridTraveler tabulation

⌨️ (03:34:32) tabulation recipe

⌨️ (03:37:59) canSum tabulation

⌨️ (03:53:01) howSum tabulation

⌨️ (04:07:21) bestSum tabulation

⌨️ (04:20:50) canConstruct tabulation

⌨️ (04:38:06) countConstruct tabulation

⌨️ (04:50:23) allConstruct tabulation

⌨️ (05:07:44) closing thoughts

⭐️ Special thanks to our Champion supporters! ⭐️

🏆 Loc Do

🏆 Joseph C

🏆 DeezMaster

—

Learn to code for free and get a developer job:

Read hundreds of articles on programming:

And subscribe for new videos on technology every day:

Calvin TDamn this guy was the instructor for app academy. His explanations actually put me on the track to understanding this crazy world of code. So glad he’s back on the scene!!!

Coderbytewe meet again! thanks for watching -Alvin

Calvin T@Coderbyte ooooo you just got a new sub.

Willson Mock@B Q is there a video link for his data structures and programming videos?

Shekhar Neupane@Coderbyte completely off-topic question if you don’t mind: What microphone are you using?

Sourav A SIt took me a week to finish this tutorial.

This tutorial is just pure gold.

I always found it hard to understand time complexity for recursive solutions. But this video explains it perfectly.

This is probably the best tutorial on dynamic programming. I can’t believe you’re giving such quality content for free…

Budagreed, this content is beyond awesome..

one punchbut do you understand the tabulation part? I don’t… But it is great content

Tak Irr01:04:10 – OBVIOUS MISTAKE??? Did he forgot to calculate space occupided by THE CACHE? Space should be O(n * m), not O(n + m) OMG

wildhrushka@Sourav A S Why, you’re practically Speedy Gonzales compared to me

Damien Spectrewhat software is he using to design the trees etc? looks handy to convey system design

RAJU RAWATAfter getting frustrated from these dynamics programing, after hunting to know the real concepts in books, articles, online paid courses, YouTube videos, finally got this here and that too free. I can’t believe this. He teaches like crazy. Thanks a lot.👍

QuancyAlvin is amazing. He currently works for google right now

CalculatorThat’s because he is crazy

Tak IrrHe’s crazy – 01:04:10 – OBVIOUS MISTAKE – he forgot to calculate space occupided by THE CACHE. Space is O(n * m), not O(n + m) OMG OMG OMG

John Van SchultzThis is one of the best videos on both recursion and dynamic programming I’ve ever seen. Thank you for making this available and sharing this knowledge with the programming community.

Bhargav PandyaMan, Alvin, I watched your Graph Algorithms course first and I absolutely loved it! I saw people there, recommending this legendary course and I just knew I had to come here! Every single second watching this video was completely worth it!

There is no way I can praise your explanation enough Alvin! There just is not!

After this going through this video, I went from literally have no clue whatsoever about what dynamic programming even means, to completely falling in love with this subject. I would surely indulge myself into this subject, and I believe that this video right here is simply the best entry point for any developer out there who is willing to learn this subject.

Thanks Alvin. I am really very grateful!!

YTGLink

John Leal1:04:12 The number of paths of [2,3] is the same as [3,2], so the function can be optimized a little more by sorting the keys: if m<=n then key = m + ',' + n else key = n+','+m .

guillep2kThe goal was to teach us the ropes, not to make the most efficient code possible. In fact, he specifically mentions that when solving the fib problem with arrays. There’s of course a much simpler way to do it, but he says it’s beyond the point. There are other optimizations that could be done: for instance, in the last problem, if we determine allocation is slow, redundant solutions could be eliminated by encoding the solutions as strings and using them in a map (e.g. map[string] bool = {“a,a,a,a” = true, “aa,aa” = true, “aaa,a” = true, “a,aaa” = true }), that way we don’t need to store similar solutions with all the possible a’s, just the first occurrence. Again, beyond the point.

AvighnaOr you could write this as key = std::to_string(std::min(m, n)) + “,” + std::to_string(std::max(m, n))

Anthony ArmourFound the comment I was looking for lol

ARJUN S@Kumaran P if (key === (m,n) || key === (n,m)) if(n>m) return(n,m) else return (m,n). I think he purposefully omitted it to decrease complexity.

Ayush Agarwal 4-Year B.Tech. Electronics Engineeringsame I was thinkihng , he mentioned it but did not add it to his code

krisnrgPhenomenal teacher, I’ve got an hour left and even though I’ve fumbled my way through similar problems I feel I understand everything much better. This is now my go to recommended video for recursion and dynamic coding

28_Shivam Dhirdoes he teach backtracking in the video ? Haven’t started watching it.

Exploring Natural beauty !@28_Shivam Dhir not specifically but discussed in some questions

Joshua BensonThis course just proves that when you go through each minute detail of a problem in a calm and precise manner, while also hinting at the obvious even, a student is much more likely to pick up on the subject. Judging by all the other comments, slower people like myself are starting to get the concept. 🤣

Fantastic coure, thank you very much for uploading this piece.

INGA probatoremThe author did not include in the compute complexity the access of the memoized data. For the fibonacci, the algorithm can be optimized to o(1) instead of o(n).

INGA probatoremo(1) for storage.

SnugglyTechThis is hands down the best crash course on dynamic programming. After struggling for so many hours on dp, I actually feel that I understand the logic and process for tackling dp problems now. Thank you for this amazing video!

Neil BruceSigned in to give my appreciation for all your hard work, and GREAT work, putting together this series. Easily the best teaching series on the subject I’ve seen. Only a few errors that are easily overlooked. Only issue I had was I was converting the problems into C++, but that’s not a knock on the series, if anything, the fact that I was so easily able to convert your solutions to C++ is indicative of a thorough explanation of the problems rather than just coding examples.

Thanks! I wish you did more!

king kai xyzThe visualization and break down of these concepts are so well done. Kudos!

aYtSimply THE best dynamic programming course on youtube, wonderfully explained.

The course made understanding the difficult concepts a breeze.

Loved the progression of problems, even the harder ones felt easy after understanding the basic strategy and the recipe.

Thank you freeCodeCamp and Alvin.

Mohammad Ghaznavifirst time seeing a GOLDEN -COMMON- comment on youtube

(sorry… I played too much hearthstone recently…)

kreo debunkof cource it is the beas, since for example iterative approach is not shown 😀

Tunde Adegbola@Mohammad Ghaznavi

Me too. First time seeing one.

How does one get it?

Mohammad Ghaznavi@Tunde Adegbola It’s probably because he/she donated to freecodecamp via youtube in some way.

Yoif a + c = b then why did the chicken cross the road.

smurfandturf3:52:52 the space is actually the size of the largest value in the numbers array, (due to growing the array to i + num) which could be way larger than the target value (unless I am misunderstanding and the array becomes sparsely represented for a huge index so not memory hungry)

Bernhard BaumgartnerI’ve never seen anyone before who was able to better and more clearly explain dynamic programming. The way you’re leading us there step by step and also how the material is presented is outstanding. I’m very impressed Good Sir 🙂 Thank you very, very much 🙇

Praful ParasharGreat video !!

Best one out there for DP.

Personally, I feel better to work through subsets generation or having different combination through memoization technique.

While for grid problems in DP, tabulation is best to visualise and solve as well.

HindigoAlthough I’m not a programmer by trade, my line of work sometimes demands some rather tricky coding, and I’m sure this intro to dynamic programming will prove to be quite helpful. Can’t thank you enough for making it freely available.

Chris AlvinoThis is a great tutorial for anyone really wanting to learn this well. Very detailed and thorough. If I was new to DP this would be a good pace. It’s a little slow for a refresher, but otherwise fantastic.

Coco L'AsticotLearning to code by myself, this course brought me so much.

I didn’t know anything about dynamic programming, not much about time and space complexity.

Now I wouldn’t say that i master it of course, but with those great explanations and examples I happened to cruise through all these exercises with ease.

I am genuinely shocked to see how easy it is for me now, as those problems just seemed impossible before and their solutions looked like witchcraft.

Thank you so much, this is a wonderful course !

diynevalaIn best sum could be hugely optimized by ordering the numbers array in descending order, thus making the tree branches shorter (substract bigger values from the target, less steps to reach 0).

*Edit* Alvin mentions that this is an incorrect assumption, but I will stand behind it. Taking the smaller numbers first will dive deep into the tree, whereas big numbers will find or fail sooner and thus result shorter answers faster. In Alvin’s example he will get 1,1,1,1,1,1,1,1; 1,1,1,1,4; 4,1,1,1,1; and so on before finding 4,4. Descending order will only find 5,1,1,1;

Also if there is a sum with 2 numbers found, there is no point in searching deeper than that in other branches.

Justin SmithBefore doing memoization on grid-traveler, the base conditions could use some simplification:

if(m === 0 || n === 0) return 0;

if(m === 1 || n === 1) return 1;

This should greatly cut down the number of recursions even before memoization. I am not sure why only the case of a (1,1) grid is returning 1. It should be any (n,1) or (1,n) provided that n > 0. A single column or single row has only one solution.