#C224. Contains Balanced Substring
Contains Balanced Substring
Contains Balanced Substring
Given a string s
consisting only of the characters 'a' and 'b', determine whether it is possible to rearrange its characters so that the resulting string contains at least one balanced substring. A substring is said to be balanced if it contains an equal number of 'a's and 'b's. In other words, for a balanced substring, the condition
[ n_a = n_b ]
must hold, where n_a
and n_b
represent the counts of 'a' and 'b', respectively.
Your task is to print True
if such a balanced substring exists after any possible rearrangement, and False
otherwise.
inputFormat
The input is provided from stdin and consists of a single line containing the string s
composed exclusively of the characters 'a' and 'b'.
outputFormat
Output to stdout the string True
if it is possible to rearrange the given string so that it contains at least one balanced substring, otherwise output False
.
False