FastPrepMinimum Anagram Period
Problems/Minimum Anagram Period

Minimum Anagram Period

Visa logoVisa● MediumNEW GRADOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source provides the core task, lowercase-string constraint, custom input format, and worked samples. The judged task matches the visible source at about 99%.

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

Examples

Example 1

inputStr = "abcbcacba"return = 3

Split the string into abc, bca, and cba. The three blocks are anagrams, and no smaller block length works.

Example 2

inputStr = "ababbaab"return = 2

The blocks are ab, ab, ba, and ab. Every block has one a and one b.

Example 3

inputStr = "aaaa"return = 1

Every one-character block is the string a, so the minimum valid length is 1.

Constraints

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

More Visa problems

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • House RobberPHONE SCREEN · Seen Nov 2026
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public int getAnagramPeriod(String inputStr) {
      // write your code here
    }
}
Checking account…