Dsa
Strings
Hard
Anagrammatic Periodic Partition
A string S is 'Anagram-Periodic' with period L if S can be divided into segments of exactly length L such that every segment is an anagram of every other segment. Given a string S, find the smallest length L such that L divides the total length of S and S is Anagram-Periodic with period L.
Input Format:
A single string S.
Output Format:
An integer representing the smallest L.
Example:
Input:
abccbaacb
Output:
3
Explanation: Length 9. Possible L: 1, 3, 9. L=1 (a,b,c... no), L=3 (abc, cba, acb... yes, all are anagrams). L=3 is smallest.
Key concepts
anagramsdivisibilitystring-logic
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now