gerrymander solution

I wanted to know for which test case my code produces wrong output , bcoz i have failed to pass few test cases



plz help me

1 Like

You’re failing on this test case:

1 5
1 0 0 0 0

Expected output:


Your output:


Do look at your else block, I think that fixing it will be enough enough to get your AC :slight_smile:

1 Like

Found your bug. There can be cases when j>o2. For that, your i in your inner loop, given i=o2+j (line 29), can exceed the total size of the array after a couple of iterations. What you can do to fix this is to do i=j%o2+o2 instead, to make sure that the first iteration is within the first range.

Your link is invalid, please edit it to

1 Like

thanks for letting me know

i fixed else part still getting same result
link -

I tried more test cases, apparently you also have an error in your first if block. Try this test case:

9 3
0 1 0 0 0 0 0 0 0 0 1 1 0 1 0 0 1 1 1 0 1 0 1 1 0 0 1

The correct output is 0 while your code is giving output 1. Hope you find that bug.

1 Like

thanks bro i got it
In first for loop condition I wrote j<o1 BUT it should be j<o2
Thanks dude :slight_smile:
BTW how u obtained the input(above one) for which my code produced wrong answer

1 Like

Oh that’s great! Just generated random input to check your program with a while loop :))