Minimum Anagram Period
Problem statement
You are given a string inputStr containing lowercase English letters.
Choose a positive block length p that divides inputStr.length. Split the entire string into consecutive blocks of length p. A block length is valid when every block is an anagram of every other block, meaning that all blocks have identical character frequencies.
Return the minimum valid block length.
Function
getAnagramPeriod(inputStr: String) → intExamples
Example 1
inputStr = "abcbcacba"return = 3Split the string into abc, bca, and cba. The three blocks are anagrams, and no smaller block length works.
Example 2
inputStr = "ababbaab"return = 2The blocks are ab, ab, ba, and ab. Every block has one a and one b.
Example 3
inputStr = "aaaa"return = 1Every one-character block is the string a, so the minimum valid length is 1.
Constraints
1 <= inputStr.length <= 10^5.inputStrcontains only lowercase English letters.