> For the complete documentation index, see [llms.txt](https://gopavasanth.gitbook.io/code/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gopavasanth.gitbook.io/code/sde-problems/day15-string.md).

# Day15: (String)

[**Longest Palindrome in a string**](https://leetcode.com/problems/longest-palindromic-subsequence/submissions/) **(DP)**\
**Solved on: Aug 4th 2020**

```cpp
int longestPalindromeSubseq(string s) {
    int n=s.size();
    int arr[n][n];
    for (int i=0;i<n;i++) {
        for (int j=0; j<n;j++) {
            if (i==j ) {
                arr[i][j] = 1;
            } else {
                arr[i][j] = 0;                    
            }
        } 
    }
    
    for (int cl=2; cl<=n;cl++) {
        for (int i=0;i<n-cl+1;i++) {
            int j=i+cl-1;                
            if (s[i] == s[j] && cl==2 ) {
                arr[i][j] = 2;
            }
            else if (s[i] == s[j] ) {
                arr[i][j] = arr[i+1][j-1] +2;
            }
            else if (s[i] != s[j] ) {
                arr[i][j] = max(arr[i][j-1], arr[i+1][j]);
            }
        }
    }
    return arr[0][n-1];
}
```

[**Reverse words in a given string**](https://practice.geeksforgeeks.org/problems/reverse-words-in-a-given-string/0)\
Solved on : 6th Sep 2020

```cpp
n=int(input())
for i in range(n):
    s=input().split('.')
    s=s[::-1]
    l=[]
    k=""
    for item in s:
        k=k+item+"."
    print (k[:-1])
```
