One Count Problem

My code https://ide.codingblocks.com/s/73197 1 is not passing the test cases. Can you please explain where it is going wrong ?

In the sample test cases, there can be two possible correct outputs (due to the alternating zeros and ones). My code gives the other output than that mentioned in there. I hope that isn’t causing any problems ?

Hi akshay
can you plz explain your approach or put comments in your code so that i can understand your approach.

Hey Aastha,
I have commented my code here https://ide.codingblocks.com/s/77352
For an overall understanding of my approach you can read Tushar Kumar’s hint here 1 Count Problem
Hope this helps

your code is not working for the following below test case
7 0
0 1 0 0 0 1 0
output: 0
0 0 0 0 0 0 0
expected output:
1
0 1 0 0 0 1 0