Same number letters
R, 106 bytes
function(s){for(A in L<-LETTERS)s=sub(A,strrep(A,max(x<-+s-+Map(gsub,L,'',s,T))-x[A]--1),s,T);s}
"+"=nchar
Try it online!
Base R approach :
- stealing some ideas from @J.Doe R+stringr approach, I saved 26 bytes !
- another 5 bytes saved using @J.Doe suggestion to abuse R
+
operator
Perl 6, 82 bytes
-3 bytes thanks to nwellnhof
->\a{a.=lc.=subst($_,$_ x a.comb(/<:L>/).Bag.values.max+1-a.comb($_))for 'a'..'z'}
Try it online!
Takes a mutable string and modifies it in place.
Explanation:
->\a{ # Anonymous code block that takes a mutable string }
a.=lc; # Lowercase
for 'a'..'z' # For each letter
.=subst( ) # Substitute
$_, #The first occurrence of the letter with
$_ x #The letter repeated
a.comb(/<:L>/).Bag.values.max # The count of the most common letter
+1 # Plus 1
-a.comb($_) # Minus the count of that letter already in the string
05AB1E, 16 bytes
lDáÙSйls¢Zα>×.;
Try it online!
Explanation
l # convert input to lowercase
D # duplicate
á # keep only letters
Ù # remove duplicates
S # split to list of chars
Ð # triplicate
¹ls¢ # count the occurrences of each letter in lowercase input
Zα # absolute valuue with max occurrence
> # increment
× # repeat each unique char that many times
.; # replace the first occurrence of the char in lowercase input with this