Now start filling the table from the diagonal first, as the diagonals represent a single element (the start and end points will be the same, which means it is the same element). And if there is one character, then the length of the palindromic subsequence is 1. Hence, all the diagonals will be filled with the value 1.

SNIPPET
1grid[i][j] = 1