AlgoUniversity
  • Go Back
Discussion
Semi Alternating Substring :

Author

Akshay Sharma

Difficulty Level : Medium

Submissions : 378

Asked In : Microsoft

Marks :100

: 4 | : 0

Given a string S containing only character a and b . A substring (contiguous fragment) of s is called semi-alternating substring if it doest not contains three identical consecutive characters. In other words, It does not contain either 'aaa' or 'bbb' substring .

Note that te wholse S is its own substring

Input

First line of test case contains a string S ($$$1\le S \le 10^5$$$)

Output

For each output print the longest semi-alternating substring

Examples

Input
abaaaa
Output
4
Input
babba
Output
5

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.