A word game highlights the longest "mirror" hidden in a string s: a subsequence (characters kept in order, others skipped) that reads the same forward and backward.
Write longestMirror(s) that returns the length of the longest palindromic subsequence of s.
Input: s = "racecars" Output: 7
racecar: skip the final s.
Input: s = "abcd" Output: 1
No letter repeats, so any single letter is the longest mirror.
1 <= s.length <= 1000s contains only lowercase English letters.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #543 Longest Mirror Subsequence. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.