Minimum Anagram Period
Problem statement
You are given a lowercase string inputStr.
Choose a positive block length p that divides inputStr.length. Split the string into consecutive blocks of length p. The length is valid when every block is an anagram of every other block.
Return the minimum valid block length.
Function
getAnagramPeriod(inputStr: String) → intExamples
Example 1
inputStr = "ababbaab"return = 2Split the string into ab, ab, ba, and ab. All four blocks are anagrams, and no block length smaller than 2 works.
Example 2
inputStr = "abcabc"return = 3The two blocks abc and abc match. Lengths 1 and 2 do not produce blocks with equal character counts.
Example 3
inputStr = "aaaa"return = 1Every one-character block is the string a.
Constraints
1 <= inputStr.length <= 10^5.inputStrcontains only lowercase English letters.