[Community Puzzle] Create the longest sequence of 1s


Send your feedback or ask for help here!

Created by @Waffle3z,validated by @pluieciel and @RaulButuc.
If you have any issues, feel free to ping them.


I’ve got code that tests 100% and fails to pass validators #3 and #6.

So I’m complaining here.


I didn’t verify my theory with the last testcase and validator, but my guess:
you take groups of 1s and compute the length of two consecutive groups + 1. You don’t check, how many 0s are between, as this will only work when there is just one 0.

I added some more test cases, hopefully they will clarify what to do.

Oh, I know what that code did wrong.
I’m just complaining about the moderation O:-)

That’s exactly what I assumed :smiley:

1 Like


Every test is done succesffully, but validator 4 (50 bits) fails. Do you have any idea why?

1 Like

I don’t know how your solution might be handling it differently from every other case but I’ve switched the test case with the validator case for 50 bits so you can see it.


I done every test successfully, but validators 5, 7 and 11 fails.

I’ve added those validators as extra test cases.

Hi there, is there any hints or sth to try to solve this puzzle? On javascript I am having a hard time with this one and can’t find anything helpful online.

Thank you!

I break the string into sections of 1s. So a string of length 1000 can be reduced into a few dozen sections or less. Brute force to find which two adj sections can be combined into the longest all-1s.

1 Like

Hi, thanks @java_coffee_cup,

I wonder what if there is no 1s and it’s just a string of 0? you cannot splice anything. Also for the gaps it sounds difficult to code.
I managed to find a solution (which i’m still working on) but i have to finish it: first identify 0s, then change each 0 for 1, then compare results :slight_smile:

I treated them as special cases to handle quickly

if list of section is empty
    return ans
else if list size is 1
    return ans
else normal cases
1 Like

Hi @java_coffee_cup,
At last I ended up splitting the string into sections of 1s and I found the way. This community is very helpful <3

1 Like

Looking at my own code, I think there is a missing test case: All 1s.

That would imply that no bits can be flipped.

1 Like

I have a code that passes all the tests but the validator #7 seems to pose a problem to it, can anyone tell me why ?

thank you !

Hi, i get everything right, in the IDE even in the Validators, its only the 9th which is not working, is there any possibility to see the Input of this Validator ?
Weirdly enough, it should be almost the same as IDE 9 “Whole String” is, doesn’t it ?

Hey. I’ll pm you the validator.

I have some issues. The code that I have implemented in Swift is the same structure and logic as Python, JavaScript,… Working in Python, JS,… at 100%, but not in Swift for the tests 7, 8 and 11 and validators 1, 3, 6, 7, 11, 14.

Any way to fix that issue on validators ?