[Tutor] how to find the maximum length substring with equal 'a' and 'b' ?
Steven D'Aprano
steve at pearwood.info
Mon Apr 7 00:56:13 CEST 2014
On Mon, Apr 07, 2014 at 02:27:55AM +0800, 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.
What is your question about? Are you having trouble with learning
Python, or about the algorithm?
If you tell us the algorithm to use, we can help you with learning
Python. This sounds like homework. Can you show us what work you have
already done?
In your first example, your output has 3 a's and 3 b's, but your second
example doesn't have equal a's and b's. You have:
input abababa (4 a's and 3 b's)
so the output should be ababab, not abababa.
--
Steven
More information about the Tutor
mailing list