Minimum Length of Anagram Concatenation - Problem

You are given a string s, which is known to be a concatenation of anagrams of some string t. Return the minimum possible length of the string t.

An anagram is formed by rearranging the letters of a string. For example, "aab", "aba", and "baa" are anagrams of "aab".

Input & Output

Example 1 — Equal Character Frequencies
$ Input: s = "abab"
Output: 2
💡 Note: String can be split as "ab" + "ab". Both segments are anagrams of "ab", so minimum length is 2.
Example 2 — Multiple Character Pattern
$ Input: s = "aabaab"
Output: 3
💡 Note: String can be split as "aab" + "aab". Both segments are identical anagrams, so minimum length is 3.
Example 3 — Single Character
$ Input: s = "aaaa"
Output: 1
💡 Note: All characters are the same, so the minimum pattern is just "a" repeated 4 times.

Constraints

  • 1 ≤ s.length ≤ 105
  • s consists of lowercase English letters

Visualization

Tap to expand
Minimum Anagram Pattern: "aabbab" → "ab"Input String (length 6):aabbabSplit into Pattern Length 2:aabbabAll segments are anagrams of "ab":• "aa" has 2a, 0b → anagram of "ab"• "bb" has 0a, 2b → anagram of "ab"• "ab" has 1a, 1b → anagram of "ab"Minimum Pattern Length = 2Pattern: "ab"Repeated 3 times withletters rearranged
Understanding the Visualization
1
Input Analysis
String s is made of concatenated anagrams
2
Pattern Detection
Find minimum length that divides string into valid anagrams
3
Result
Return the minimum possible pattern length
Key Takeaway
🎯 Key Insight: The minimum pattern length divides all character frequencies equally
Asked in
Google 25 Microsoft 18 Amazon 15
33.0K Views
Medium Frequency
~15 min Avg. Time
845 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen