Length of longest consecutive ones

Given a binary string A. It is allowed to do at most one swap between any 0 and 1.
Find and return the length of the longest consecutive 1’s that can be achieved.



Input Format

The only argument given is string A.

Output Format

Return the length of the longest consecutive 1’s that can be achieved.

Constraints

1 <= length of string <= 1000000
A contains only characters 0 and 1.

For Example

Input 1:
    A = "111000"
Output 1:
    3

Input 2:
    A = "111011101"
Output 2:
    7
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Length of longest consecutive ones on Interview Code Editor
Sign Up
to access hints and editorial solutions for Length of longest consecutive ones

Discussion


Loading...
Click here to start solving coding interview questions