Question: /* A string, input, which contains only letters a and b are given. A list of substrings s1, s2, .., sn is called a partition

/*

A string, input, which contains only letters a and b are given.

A list of substrings s1, s2, .., sn is called a partition for input if and only if

input == s1 + s2 + ... + sn.

A substring is balanced if it has an equal number of a's and b's.

The number of balanced substrings in a partition is called the balance number of the partition.

Among all the possible partitions of the input string, what is the maximum balance number?

Example:

input: 'abaabbabab'

output: 4 because the following partition has the highest number of balanced substrings:

'ab', 'aabb', 'ab', 'ab'

input: 'aaababbba'

output: since the string can be partitioned as ('aa', 'ab', 'ab', 'b', 'ba')

3 because the following partition has the highest number of balanced substrings:

'ab', 'ab', 'ba'

*/

var maxBalanceNumber = function(input) {

TODO:

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!