Most identical pieces
You may rearrange the letters of S in any order, then cut it into pieces that are all identical. What is the largest number of pieces you can get?
Reported in: Infosys (SP / DSE · earlier papers) (memory-based)
Input
One line: S.
Output
The largest number of identical pieces.
Constraints
1 ≤ |S| ≤ 10^5; lowercase letters.
Example 1
Input:
aabbcc
Output:
2Example 2
Input:
abcabcabc
Output:
3Example 3
Input:
zzzz
Output:
4Example 4
Input:
ab
Output:
1Hint: Every piece must hold the same number of each letter, so the number of pieces divides every letter count. The answer is the GCD of the letter counts.