[Tutor] how to find the maximum length substring with equal 'a' and 'b' ?

Alan Gauld alan.gauld at btinternet.com
Mon Apr 7 01:38:44 CEST 2014

On 06/04/14 19:27, Arup Rakshit wrote:
> Suppose, if I have the string 'aababbb', I want to get the output as
> 'aababb'. I want the output in time complexity O(N) and space complexity
> O(1). when input string is 'abababa', output should be same as input.

You will need to explain more about what you want to do.
Your two examples don't have any obvious link.
The first result is 6 characters the second is 7.
The first has equal a's and b's the second has differing
numbers and doesn't match your subject line.

What is the criteria for deciding what the output is?

Once we know that we can start worrying about whether the solution
is O(N) etc.

Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list