class Solution { // idea: longest palindromic subsequence will be length of LCS public int longestPalindromeSubseq(String s) { int n = s.length(); // reverse the string and stroe it in new string String s2 = new StringBuilder(s).reverse().toString(); int m = s2.length(); // step-1 create a matrix // t[i][j] = LCS of first i chars of s and first j chars of reversed string int[][] t = new int[n+1][m+1]; // step-2 initialise the matrix with base condition for(int i=0; i