Split a String in Balanced Strings
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
2 <= len(s) <= 100shas onlyLandR, equally many of each
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Greedy problems
- Ticket Booth ChangeEasy
- Best Job LineupMedium
- Cheapest Way to Merge PilesMedium
- Circular Delivery RouteMedium
- Cut So Each Letter Stays TogetherMedium
- Deal Into StraightsMedium
- Fewest Candies by RatingMedium
- Fewest Door VisitsMedium