Given a string, find the maximum deviation
among all substrings. The maximum deviation is defined as the difference between the maximum frequency of a character and the minimum frequency of a character.
For example, in abcaba
, a
has a frequency of 3; b
has a frequency of 2; c
has a frequency of 1. so a
has the maximum frequency, which is 3, whereas c
has a minimum frequency of 1. Therefore the deviation of this string is 3 - 1 = 2
. And we also need to find all other deviations for each of the substrings for abacaba
, the maximum among them is the answer.
I couldn't think of a better way rather than the obvious brute force approach. Thanks in advance!