<p>Given a string <code>s</code>, find <em>the longest palindromic <strong>subsequence</strong>&#39;s length in</em> <code>s</code>.</p>

<p>A <strong>subsequence</strong> is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;bbbab&quot;
<strong>Output:</strong> 4
<strong>Explanation:</strong> One possible longest palindromic subsequence is &quot;bbbb&quot;.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;cbbd&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> One possible longest palindromic subsequence is &quot;bb&quot;.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 1000</code></li>
	<li><code>s</code> consists only of lowercase English letters.</li>
</ul>

class Solution:
    def lcs_memoized(self,str1,str2,m,n,memo):
        if m==0 or n==0:
            return 0
        if (m,n) in memo:
            return memo[(m,n)]
        if str1[m-1]==str2[n-1]:
            memo[(m,n)] =  1+self.lcs_memoized(str1,str2,m-1,n-1,memo)
        else:
            memo[(m,n)] = max(self.lcs_memoized(str1,str2,m-1,n,memo),self.lcs_memoized(str1,str2,m,n-1,memo))
        return memo[(m,n)]
        
    def longestCommonSubsequence(self,str1,str2):
        m = len(str1)
        n = len(str2)
        memo = {}
        return self.lcs_memoized(str1,str2,m,n,memo)

    def longestPalindromeSubseq(self, s: str) -> int:
        s_reversed = s[::-1]
        return self.longestCommonSubsequence(s,s_reversed)

        
167606