Talentd
FleetCode

3138. Minimum Length of Anagram Concatenation

Medium39.8% acceptance2 companies

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".

Example 1:

Input: s = "abba"

Output: 2

Explanation:

One possible string t could be "ba".

Example 2:

Input: s = "cdef"

Output: 4

Explanation:

One possible string t could be "cdef", notice that t can be equal to s.

Constraints:

  • 1 <= s.length <= 105
  • s consist only of lowercase English letters.

Asked at 2 companies

Hints open one at a time

Hint 1
The answer should be a divisor of s.length.
Hint 2
Check each candidate naively.
13:15
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def minAnagramLength(self, s: str) -> int:
3
Starter codePython 3Spaces: 4
Examples
Input
"abba"
Input
"cdef"
Input
"abcbcacabbaccba"
Your code is saved on this device.Solution