5
var checkPartitioning = function (s) {6
// create a dp that will represent the starting and ending index of a substring7
// if dp[i][j] is true that means that the string starting from i and ending at j is a palindrome8
const dp = new Array(s.length)10
.map(() => new Array(s.length).fill(false));12
// all substrings of length 1 are palindromes so we mark all matching indices as true13
for (let i = 0; i < s.length; i++) {17
// slowly grow the substring from each index18
// we will know the substring is a palindrom if the substring prior was a palindrome20
let lengthOfSubString = 2;21
lengthOfSubString <= s.length;25
let startingIndex = 0;26
startingIndex + lengthOfSubString <= s.length;29
// if it's not the same character, then it can not be a palindrome30
if (s[startingIndex] !== s[startingIndex + lengthOfSubString - 1])34
lengthOfSubString <= 3 ||35
// this checks if the prior substring was a palindrome36
dp[startingIndex + 1][startingIndex + lengthOfSubString - 2]38
dp[startingIndex][startingIndex + lengthOfSubString - 1] = true;43
// find out if any 3 of the partitions are palindromes44
for (let i = 0; i < s.length; i++) {45
for (let j = i + 1; j < s.length; j++) {46
if (dp[0][i] && dp[i + 1][j] && dp[j + 1][s.length - 1]) return true;50
// if we haven't found a partition, return false