FastPrepMinimum Anagram Period

Minimum Anagram Period

Wells Fargo logoWells Fargo● MediumNEW GRADOA
Learn

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) → int

Examples

Example 1

inputStr = "ababbaab"return = 2

Split 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 = 3

The two blocks abc and abc match. Lengths 1 and 2 do not produce blocks with equal character counts.

Example 3

inputStr = "aaaa"return = 1

Every one-character block is the string a.

Constraints

  • 1 <= inputStr.length <= 10^5.
  • inputStr contains only lowercase English letters.

More Wells Fargo problems

See Wells Fargo hiring insights
public int getAnagramPeriod(String inputStr) {
  // write your code here
}
inputStr"ababbaab"
expected2
Checking account…