pyassistant

Longest substring that can be permuted into a palindrome

Given a string s consisting of lowercase English letters, find the length of the longest substring of s that can be rearranged (permuted) to form a palindrome. A substring can be permuted into a palindrome iff at most one character has an odd count in that substring. Return the length of the longest such substring. Constraints: 1 <= len(s) <= 2e5. Only lowercase letters 'a' to 'z' appear in s. Example: For s = "abacaba", the longest substrings that can be permuted into palindromes include "abacaba" (already a palindrome) of length 7, so the answer is 7.

Example:

Input:
("abacaba")
Output:
7

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.