Question
Balanced strings are those who have equal quantity of L and R characters. Given a balanced string s split it in the maximum amount of
Balanced strings are those who have equal quantity of "L" and "R" characters. Given a balanced string s split it in the maximum amount of balanced strings. Return the maximum amount of splitted balanced strings Example 1: input: "RLRRLLRLRL" output: 4 Explanation: "RLRRLLRLRL" can be split into "RL", "RRLL", "RL", "RL", since each substring contains the same number of "L" and R" Example 2: input: "RLLLLRRRLR" output: 3 Explanation: "RLLLLRRRLR" can be split into "RL", "LLLRRR","LR", since each substring contains the same number of "L" and "R" Example 3: input: "LLLLRRRR" output: 1 Explanation: "LLLLRRRR" can be split into "LLLLRRRR" Example 4: input: "RLRRRLLRLL" output: 2 Explanation: "RLRRRLLRLL" can be split into "RL", "RRRLLRLL", since each substring contains the same number of "L" and "R" Please write a program to achieve this goal and name it CountBalancedStrings.java
public class CountBalancedStrings { public static void main(String[] args) { // program starts running here. } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started