A number of coding interview problems solved using dynamic programming. It includes my solutions in Python to the questions in the fantastic freeCodeCamp course by Alvin Zablan. Check it out here.
- Memoization = Recursion (Algorithm) + Dictionary (Data Structure)
- Draw a tree:
- The nodes are the inputs.
- The edges are the transtions, reductions, or shirnking of the problem.
- The leaves are the base case.
- Draw a tree:
- Tabulation = Iteration (Algorithm) + List (Data Structure)
- Draw a table:
- The size of the table is the size of the inputs + 1.
- For an input of 3 and 3, have a 4 x 4 table/array.
- Draw a table:
- Draw a tree. The nodes are the input. The edges are the transition/reduction. The leaves are the base case.
- Write the recursion algorithm which is the brute force solution.
- Code it.
- Improve the performance by adding a memo which will improve the time complexity by sacrificing some space.
- Add a memo dictionary with default value None which you then intialize as an empty dictionary.
- Add a memo base case checking if the solution is already in the memo and if so, just return it.
- If not solve it recursively. Save the result in the memo, then return it.
- Create a table. It's size is the input + 1.
- Initialize all values with the default value of the base case.
- Seed the table with the base case.
- Iterative over the table/list. Use the current location/item to calculate the next/future location.
- Return the last item in the table/list.
- Is there a way?
- What's one way?
- What the best way?
- How many ways are there?
- What are all the ways?
- Fibonacci Number:
- What's the nth Fibonacci number?
- Travel in Grid:
- How many ways to travel in a grid of m x n from start to end?
- Making the Sum out of Numbers | Making the Change out of Coins:
- Can you make sum using the following number categories?
- What's one way to make the sum using these number categories?
- What's the shortest way to make the sum using these number categories?
- String Construction:
- Can you construct this target string by concatenating elements from this array of strings?
- How many ways can you construct this target string by concatenating elements from this array of strings?
- What are all the ways can you construct this target string by concatenating elements from this array of strings?