#K72282. Longest Balanced Substring
Longest Balanced Substring
Longest Balanced Substring
Given a string ( s ) consisting only of the characters 'X' and 'O', your task is to find the length of the longest balanced substring. A substring is said to be ( \textbf{balanced} ) if it contains an equal number of 'X's and 'O's. For example, in the string "XXOXOOXOX", the longest balanced substring has a length of 8.
Note: A balanced substring is not necessarily contiguous to the ends of the string.
inputFormat
The input consists of a single line containing a non-empty string ( s ) comprised only of the characters 'X' and 'O'.
outputFormat
Output a single integer which is the length of the longest balanced substring of ( s ).## sample
XXOXOOXOX
8
</p>