Simplified grouping of letters
Use a dynamic upper bound
Removed useless array conversion
Square optimization