# What is the Time & Space complexity of finding the longest palindromic substring using dynamic programming in a string?

## What is the Time & Space complexity of finding the longest palindromic substring using dynamic programming in a string?

The time complexity of the Dynamic Programming based solution is O(n^2) and it requires O(n^2) extra space. We can find the longest palindrome substring( LPS ) in (n^2) time with O(1) extra space.

**Which is the longest palindrome?**

The longest palindrome in English is often considered tattarrattat, coined by James Joyce in his 1922 Ulysses to imitate the sound of a knock on the door.

### What is the length of the longest palindromic subsequence?

1) Optimal Substructure: Let X[0..n-1] be the input sequence of length n and L(0, n-1) be the length of the longest palindromic subsequence of X[0..n-1]. If last and first characters of X are same, then L(0, n-1) = L(1, n-2) + 2. Else L(0, n-1) = MAX (L(1, n-1), L(0, n-2)).

**How do you find the longest palindromic substring in Java?**

Longest Palindromic Substring solution in Java To solve this, we maintain a 2D array palindrom[i][j] which is set to true if the substring s(i,j) is a palindrome, otherwise, it is set to false . We also maintain a variable to keep track of the longest palindromic substring found so far ( longestSoFar ).

## How do you find the longest palindromic substring of a given substring in Java?

**Which of the following methods can be used to solve the longest palindromic subsequence problem?**

1. Which of the following methods can be used to solve the longest palindromic subsequence problem? Explanation: Dynamic programming, Recursion, Brute force can be used to solve the longest palindromic subsequence problem.

### How do you find the number of palindromes?

So, for example, if your alphabet consists of the 26 lowercase letters a-z, and you want a string with 9 characters, then N=26 and the string has length 2k+1 with k=4; therefore the number of possible palindromes is 265=11,881,376.