Why these 2 solutions are not working for this Question?

Why these 2 solutions are not working for this Question?

Regarding 2 of your solutions, your first solution will exceed the time limit since it is an O(n * n) solution. Besides, the 2nd solution is infact quite right, but you are missing some edge cases, where the max number of 1s occur from the starting of the array or just at the end of the array. So, you need to take them into account also.

I have pushed 0 in zeroes array and I think that will handle the case when beginnings are 1 but It is not giving correct ans.
Also I think I am missing One case where all the elements in the array will be 1.

did you figure out the mistake in your solution yet ?

Is It that,
I also pushed now zeroes.push_back(n)
So When One of element in zeroes vector is either 0 or n then I don’t have to do extra -1 else do -1.

just push -1 before the loop and n after the loop and then do your computation. And it will work just fine.

Okay Understood.
Thanks a lot.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.