Minimum Insertion Steps to Make a String Palindrome LeetCode solution in JavaScript
1var minInsertions = function (s) {2const len = s.length;3const dp = new Array(len).fill(0).map(() => {4return new Array(len).fill(-1);5});67const compute = (i = 0, j = len - 1) => {8if (i >= j) return 0;910if (dp[i][j] != -1) return dp[i][j];1112if (s[i] == s[j]) return compute(i + 1, j - 1);1314return (dp[i][j] = Math.min(compute(i + 1, j), compute(i, j - 1)) + 1);15};16return compute();17};