function longestHuiWenSubString(S) {
const n = S.length;
let start = 0, maxLength = 1;
const dp = new Array(n);
for (let i = 0;i < n;i++) {
dp[i] = new Array(n);
dp[i][i] = true;
}
for (let L = 2;L <= n;L++) {
for (let i = 0;i < n - L + 1;i++) {
if (S.charAt(i) === S.charAt(i + L - 1)) {
if (L === 2) dp[i][i + L -1] = true;
else dp[i][i + L - 1] = dp[i + 1][i + L - 2];
if (dp[i][i + L - 1]) {
if (L > maxLength) {
start = i;
maxLength = L;
}
}
} else {
dp[i][i + L - 1] = false
}
}
}
return S.slice(start, start + maxLength);
}
console.log(longestHuiWenSubString("azkzab"))
console