#K38842. Minimum Deletions to Equalize Characters
Minimum Deletions to Equalize Characters
Minimum Deletions to Equalize Characters
You are given a string \(S\) consisting of lowercase Latin letters. Your task is to determine the minimum number of deletions required so that all the remaining characters in the string are equal.
Formally, let \(S\) be a string of length \(n\), and let \(f(x)\) denote the frequency of character \(x\) in \(S\). The answer can be computed by the formula:
\(\text{answer} = n - \max_{x} f(x)\),
where \(\max_{x} f(x)\) is the maximum frequency among all characters in \(S\).
For example, if \(S = \texttt{aabbcc}\), then the maximum frequency is 2, and the minimum deletions required is \(6 - 2 = 4\).
inputFormat
A single string (S) ((1 \leq |S| \leq 10^6)) made up of lowercase Latin letters. The input is read from standard input (stdin).
outputFormat
Print a single integer: the minimum number of deletions required, with the output sent to standard output (stdout).## sample
aabbcc
4