#K6396. Maximum Balanced Substrings
Maximum Balanced Substrings
Maximum Balanced Substrings
You are given a string s
which consists solely of the characters 'L' and 'R'. A balanced substring is defined as a substring where the number of 'L' characters is equal to the number of 'R' characters, i.e. $$|L| = |R|$$. Your task is to partition the string into the maximum number of balanced substrings. If it is not possible to form any balanced substring, output 0.
Example:
Input: RLRRLLRLRL Output: 4
Explanation: One way to split the string is "RL", "RRLL", "RL", "RL" which gives 4 balanced substrings.
inputFormat
The input consists of a single line containing the string s
composed only of the characters 'L' and 'R'.
outputFormat
Output a single integer which is the maximum number of balanced substrings that can be obtained by partitioning the input string.
## sampleRLRRLLRLRL
4