Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Split a String in Balanced Strings

XPChallenge Points: 10
levelLevel: Easy

You are given a string s consisting only of the characters 'L' and 'R'.
A balanced string is defined as one that contains an equal number of 'L' and 'R' characters.
Your task is to split the given string into the maximum number of balanced substrings, and return this number.
Each substring after splitting must be balanced on its own.

Example 1:

Input: s = "RLRRLLRLRL"

Output: 4

Example 2:

Input: s = "RLRRRLLRLL"

Output: 2

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result