FunctionRacerProblemsRace

Split a String in Balanced Strings

EasyGreedyPython, JavaScript, TypeScript, Java, C++

s has the same number of L and R characters. Cut s into as many pieces as possible so that each piece also has equally many L and R. Return the number of pieces.

Example 1

s "RLRRLLRLRL"
returns 4

Pieces RL, RRLL, RL, RL.

Example 2

s "LLLRRR"
returns 1

Only one piece is possible.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Greedy problems