104. Split into Balanced Strings
EasyGreedyCounting
A balanced string has equal numbers of L and R. Split the given balanced string into the maximum number of balanced substrings and print that number.
Input format
A single line of L and R characters.
Output format
The maximum number of pieces.
Example 1
Input
RLRRLLRLRL
Output
4
Example 2
Input
RLLLLRRRLR
Output
3
Constraints
2 ≤ |s| ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…