Longest Perfect Anagrams
HardAsked in:Amazon•Stage:Online Assessment
stringhash_tablesliding_window
Problem Statement
Given a string S of length n, find the length of the longest contiguous substring that can be rearranged to form a palindrome (a perfect anagram). The substring must be contiguous and you may reorder its characters arbitrarily to check if it can become a palindrome.
Input Format
A single line containing the string S consisting of lowercase English letters. n = |S|.
Output Format
Print a single integer – the maximum length of such a substring. If no such substring exists, output 0.
Constraints
- 1 <= n <= 10^5
- S contains only lowercase English letters