xyyx and abccba are tidy palindromes, while xyx (odd length) and xxxx (equal neighbors away from the middle) are not.
You are given a string text. Pick a subsequence of it (some of its letters in their original order, not necessarily adjacent) that is a tidy palindrome, and return the greatest possible length. If there is none, return 0.text="cabbac" → 6
The whole string is an even-length palindrome, and the only equal neighbors are the middle pair bb.
text="aaaa" → 2
aaaa does not count, since equal letters sit next to each other outside the middle. The best is aa, of length 2.
text="xyz" → 0
No letter repeats, so there is no suitable palindrome at all.
text) ≤ 250text consists of lowercase English letterstext="cabbac"
6
Run checks the first 3 tests in your browser. Submit checks all 123 tests on the server, hidden ones included.