class Solution { public String longestPalindrome(String s) { String s2 = new StringBuilder(s).reverse().toString(); int n = s.length(); int m = s2.length(); // create a matrix int[][] t = new int[n+1][m+1]; // intialise the matrix with base condition for(int i=0; i maxLength) { maxLength = currentLength; endIndex = i-1; } } } } } return s.substring(endIndex - maxLength + 1, endIndex + 1); } }