Now we'll show you how to fill this table so that we can find the longest palindromic substring. We will fill the diagonal first because the diagonal indicates a single element (for example, if the starting point is 0
and the ending point is also 0
, then what we're operating on is just the substring m
). See the diagram below.
The logic is similar to our brute force solution-- we want to find the substring and check if it is a palindrome or not. If it is a palindrome, then fill True
in the table at that position. With that said, let's fill up the diagonal.