Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges

freeCodeCamp.org · 4.7M views · 2020 · 5:10:02

Open on YouTube

Algorithms & data structuresEducation & learningSoftware practice, open source & careerscourse

Why Stack Overflow recommends it

Stack Overflow users link it when asking about or explaining specific problems from the course, such as howSum, canConstruct, grid traveler and memoization, and when they want a beginner-friendly introduction to dynamic programming.

Recommended by 8 people across 8 different months, 2020 to 2023.

What it is

A five-hour freeCodeCamp course by Alvin Zablan of Coderbyte that teaches dynamic programming through animated visualizations. It works through memoization and tabulation problems like fib, gridTraveler, canSum, howSum, bestSum and canConstruct, with solutions written in JavaScript.

What people said

Recommends Yann Hamonou · 2020-12 · Stack Overflow · on “Memoization and return statements”

I am fairly new to python, stumbled upon a dynamic programming course on youtube that I thought would help me better understand the concept @ here [this video] . Now, I have been struggling to understand it... Would anyone have the time to explain the way this code works? The function takes a target sum and an array of numbers as arguments. The function should return an array containing any combination of numbers that add up exactly to the target number. def howSum(targetSum, numbers, memo = {}): if targetSum in memo : return memo[targetSum] if targetSum == 0 : return [] if targetSum < 0 : return None for num in numbers: remainder = targetSum - num remainderResult = howSum(remainder, numbers, mem

Recommends Squadrons · 2021-03 · Stack Overflow · on “Dynamic Programming problem - extending to find all possible paths to sum”

I'm doing a DP course [this video] to brush up (it's great and has helped me a ton), and one of the problems is given a target sum and a list of numbers, is there a path to the target / what is the best (shortest) path? I've solved the pathExists and bestPath problems, but was stuck thinking about a problem they didn't ask the solution to - can you list ALL paths to the solution: golang code below for best golang func BestSum(ts int, nums []int) []int { var best []int return bs(ts, nums, best) } func bs(ts int, nums, best []int) []int { if ts == 0 { return []int{} } else if ts < 0 { return nil } for _, n := range nums { rc := bs(ts-n, nums, best) if rc != nil { path := append(rc, n) if best == ni

Recommends MajoRoth · 2021-05 · Stack Overflow · on “Hamiltonian paths by total cost”

I don't know such an algorithm as you described. Thus you didn't append your brute force solution - many times you can use several methods to significantly reduce the computation time. using methods from the branch "Dynamic Programing" and in particular "memoization" for recursive algorithms. Added a link for a great video that demonstrates the concept [this video]

Recommends Newspada · 2021-06 · Stack Overflow · on “Issue in coin change implementation (Java)”

Thanks you for your help! I usually work in c++, so most of the things are passed as copy in default! I wanted to rewrite the code in this video [this video]

Recommends Arkadiusz Kulpa · 2021-10 · Stack Overflow · on “Javascript: .push is not a function”

I know this is old and practically already solved, but It didn't solve my issue directly. When searching for solutions I discovered another way to go avoid .push() method if we wanted to directly return the array. return [ ...array, b]; as explained in this video at 1:41:00 [this video]

Recommends Cardstdani · 2021-11 · Stack Overflow · on “Question regarding to Climbing Stairs Memoization Top-Down Approach”

The first return statement is inside an if condition, and it returns a value when it's already computed, in order to not compute 2 or more times the same operation. if memo.get(n): #This if is basically checking if the code has already computed the function in n return memo[n] #This line never executes if the code has already returned memo[n] in the if condition used to NOT compute multiple times the same operation memo[n] = climb(n-1, memo) + climb(n-2, memo) return memo[n] But in the second return statement, it gives the computation of climb(n-1, memo) + climb(n-2, memo) that is stored on memo[n] and has never been done before in the code execution. I suggest you to watch these videos to u

Recommends Frederick Scott Smith · 2023-01 · Stack Overflow · on “Dynamic Programming Question - What is the base case?”

Been preparing of Coding Interviews. I have been trying to beef up my dynamic programming skills and came across Alvin's awesome channel and this great video about some of the approaches to take. In one of the programming sections - The problem statement is "Can you construct the target string with the contents in an array" - he goes on to correctly use recursion as an approach. But I got stuck in his base case [this video] . He indicates for example that this should return true: canConstruct('StakeBoard', ['sta', 'te', 'bo', 'ard'] He goes on to settle the recursion base case as the following returning true by literally saying "Because to generate and empty string, you can generally take no-zero

Recommends jbk · 2023-05 · Stack Overflow · on “Is this a pass by reference/value misunderstanding that's having this method fail output as intended?”

I'm working on a solution to this problem (4hr50m in this [this video] vid): Write a function all_construct_tabular(target, word_array) to return a 2D array containing all of the ways in which the target string can be constructed by concatenating elements of the word_array. Each element of the 2D array should represent one combination that constructs target. Elements of word_array can be reused. Here's my test: it "returns a 2d array with x4 sub array elements" do result = all_construct_tabular('abcdef', ['ab', 'abc', 'cd', 'def', 'abcd', 'ef', 'c']) expect(result).to eq([['ab', 'cd', 'ef'], ['ab', 'c', 'def'], ['abc', 'def'], ['abcd', 'ef']]) end Here's my method: def all_construct_tabular(targe

Cites lordvidex · 2020-12 · Stack Overflow · on “int[] vs ArrayList<>() in memoization, dynamic programming in Java”

I recently watched a dynamic programming tutorial on Youtube explaining dynamic programming but the Tutor solved problems in JavaScript. I, on the other hand, use Java for data structures and algorithms. While implementing dynamic programming to solve a question. I discovered that I got the solution to the problem when using int[] but had wrong answer when using ArrayList<Integer> because somehow, the ArrayList already stored in the HashMap was being modified internally. Question: Write a function bestSum(targetSum, numbers) that takes in a targetSum and an array of numbers as arguments and returns an array containing the shortest combination of numbers that add up to exactly the target sum.

Cites Fares Naoui · 2020-12 · Stack Overflow · on “Why my code didn't work correct in this problem”

the grid travel problem she is basically recursion problem and this is it : grid travel problem [this video] and this is my solution: #include <stdio.h> #include <string.h> int gridtravel(int r, int c) { if (r == 1 && c == 1) return 1; if (r == 0 || c == 0) return 0; return gridtravel(r - 1, c) + gridtravel(r, c - 1); } int main() { int r, c; scanf("%i%i", &r, &c); printf("%i\n", gridtravel(r, c)); } but when I want to reduce the time complexity with solution like this I get a incorrect result: #include <stdio.h> #include <string.h> int gridtravel(int r, int c, int arr[][c]) { if (arr[r][c] != 0) return arr[r][c]; if (arr[c][r] != 0) return arr[c][r]; if (r == 1 && c == 1) return 1; if (r == 0 ||