Question bank › Strings
Dsa Strings Hard

Maximum Anagram Square

An 'Anagram Square' is a string of even length 2k where the first k characters are an anagram of the last k characters. Given a string S, find the length of the longest substring that is an Anagram Square. If no such substring exists (other than the empty string), output 0. Input Format: A single string S. Output Format: An integer representing the length of the longest Anagram Square substring. Example: Input: baabbc Output: 2 Explanation: Substrings 'aa' and 'bb' are anagram squares (k=1, length 2). 'aabb' is not (aa vs bb).

Key concepts

anagramssliding windowstring-frequency

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.