Category : dynamic-programming

I was working on a Dynamic Programming Problem and was able to code up a Javascript solution: function howSum(targetSum,numbers,memo = {}){ //if the targetSum key already in hashmap,return its value if(targetSum in memo) return memo[targetSum]; if(targetSum == 0) return []; if(targetSum < 0) return null; for(let num of numbers){ let aWay = howSum(targetSum-num,numbers,memo); if(aWay !== ..

Read more

let blocks = [ { gym:false, school:true, store:false, }, { gym:true, school:false, store:false, }, { gym:true,// and this contains gym school:true, store:false, }, { gym:false, school:true, // this block is the answer as I can find all three requirements near to this index above and below index; store:false, }, { gym:false, school:true, // this contains ..

Read more

Could anyone please let me know why the following code in c++ doesn’t work? // count number of ways to construct a target string from a given set of strings #include "bits/stdc++.h" using namespace std; int countConstruct(string target, vector<string> wordBank, map<string, int> memo = {}) { if (memo.find(target) != memo.end()) return memo.at(target); if (target == ..

Read more