Good afternoon! Here's our prompt for today.
Question/Prompt
A palindrome
is a word, phrase, or sequence that reads the same backward or forwards. A palindromic subsequence
is a palindrome derived from a sequence by deleting some or no elements from it. This subsequence is formed without changing the order of the elements in the original sequence.
Given a string s
, can you find the length of the longest palindromic subsequence of s
?

For example, if s = "bbbab"
, then the longest palindromic subsequence is bbbb
. The length of this subsequence is 4
, which is the required answer.
Constraints
- 1 <=
s.length
<= 1000 s
consists only of lowercase English letters.
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx
28
var assert = require('assert');
​
function longestPalindromeSubseq(s) {
// add your code here
return;
}
​
try {
assert.deepEqual(longestPalindromeSubseq('bbbab'), 4);
console.log('PASSED: ' + "`longestPalindromeSubseq('bbbab')` should return `4`");
} catch (err) {
console.log(err);
}
​
try {
assert.deepEqual(longestPalindromeSubseq('cbbd'), 2);
console.log('PASSED: ' + "`longestPalindromeSubseq('cbbd')` should return `2`");
} catch (err) {
console.log(err);
}
​
try {
assert.deepEqual(longestPalindromeSubseq('abbcdabbc'), 5);
console.log('PASSED: ' + "`longestPalindromeSubseq('abbcdabbc')` should return `5`");
} catch (err) {
console.log(err);
}
​
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment
We'll now take you through what you need to know.
How do I use this guide?