3844. Longest Almost-Palindromic Substring Medium
1/**
2 * [3844] Longest Almost-Palindromic Substring
3 *
4 * You are given a string s consisting of lowercase English letters.
5 * A <span data-keyword="substring-nonempty">substring</span> is almost-palindromic if it becomes a <span data-keyword="palindrome-string">palindrome</span> after removing exactly one character from it.
6 * Return an integer denoting the length of the longest almost-palindromic substring in s.
7 *
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">s = "abca"</span>
11 * Output: <span class="example-io">4</span>
12 * Explanation:
13 * Choose the substring "<u>abca</u>".
14 *
15 * Remove "ab<u>c</u>a".
16 * The string becomes "aba", which is a palindrome.
17 * Therefore, "abca" is almost-palindromic.
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">s = "abba"</span>
22 * Output: <span class="example-io">4</span>
23 * Explanation:
24 * Choose the substring "<u>abba</u>".
25 *
26 * Remove "a<u>b</u>ba".
27 * The string becomes "aba", which is a palindrome.
28 * Therefore, "abba" is almost-palindromic.
29 * </div>
30 * <strong class="example">Example 3:
31 * <div class="example-block">
32 * Input: <span class="example-io">s = "zzabba"</span>
33 * Output: <span class="example-io">5</span>
34 * Explanation:
35 * Choose the substring "z<u>zabba</u>".
36 *
37 * Remove "<u>z</u>abba".
38 * The string becomes "abba", which is a palindrome.
39 * Therefore, "zabba" is almost-palindromic.
40 * </div>
41 *
42 * Constraints:
43 *
44 * 2 <= s.length <= 2500
45 * s consists of only lowercase English letters.
46 *
47 */
48pub struct Solution {}
49
50// problem: https://leetcode.com/problems/longest-almost-palindromic-substring/
51// discuss: https://leetcode.com/problems/longest-almost-palindromic-substring/discuss/?currentPage=1&orderBy=most_votes&query=
52
53// submission codes start here
54
55impl Solution {
56 pub fn almost_palindromic(s: String) -> i32 {
57 0
58 }
59}
60
61// submission codes end
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn test_3844() {
69 }
70}
71Back
© 2026 bowen.ge All Rights Reserved.