From Codechef:
A string is considered balanced if and only if all the characters occur in it equal number of times.
You are given a string S
; this string may only contain uppercase English letters. You may perform the following operation any number of times (including zero): Choose one letter in S
and replace it by another uppercase English letter. Note that even if the replaced letter occurs in S
multiple times, only the chosen occurrence of this letter is replaced.
Find the minimum number of operations required to convert the given string to a balanced string.
Example:
For input: ABCB
Here, we can replace C
with A
, TO GET: ABAB
, where each character of the string occurs for 2 times.
So, the number of minimum operation(s)=1
.
How to make the string good?
Can I apply dynamic programming to it ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…