1D Dynamic Problems
- Decode Ways:
- https://neetcode.io/problems/decode-ways?list=neetcode150
- In this problem - the base conditions are key.
javascript dp.set(s.length, 1); - And also the way digit zero condition has been handled
- Max Product Subarray
- https://neetcode.io/problems/maximum-product-subarray?list=neetcode150
- His video solution is not right.
maxProduct(nums) {
let res = nums[0];
let curMax = 1;
let curMin = 1;
for(let n of nums){
let tmp = curMax * n;
curMax = Math.max(n, curMaxn, curMinn);
curMin = Math.min(n, tmp, curMin*n);
res = Math.max(res, curMax);
}
return res;
}
11. Longest Increasing SubSequence
- great problem!
- link - https://neetcode.io/problems/longest-increasing-subsequence?list=neetcode150
```js
lengthOfLIS(nums) {
let cache = new Array(nums.length).fill(1);
for(let i = nums.length-1; i >=0; i--){
for(let j =i+1; j < nums.length; j++){
if(nums[i]<nums[j])
cache[i] = Math.max(cache[i], 1+ cache[j]);
}
}
return Math.max(...cache);
}
- Partition Equals Subset Sum
- What a great problem https://neetcode.io/problems/partition-equal-subset-sum?list=neetcode150
- Bang on solution by Neetcode.