# Help me in solving ZEROSTRING problem

### My issue

/*problem name: Zero String , contest code:START76 please help me to rectify my code and also tell me how can i improve my approach to the problems */

include <stdio.h>

int main(void) {
int test;
scanf(“%d”, &test);
while(test–){
int size;
scanf(“%d”, &size);
char arr[size];
scanf(“%s”, arr);
int counter1=0,counter0=0;
for(int i=0;i<size;i++){
if(arr[i]==‘0’) counter0++;
if(arr[i]==‘1’) counter1++;
}
int min=counter0;
if(min>counter1) min=counter1;
if(counter0==size) printf(“0\n”);
else if(counter1==size) printf(“1\n”);
else if(counter0==counter1) printf(“%d\n”, counter1);
else if(counter1==1) printf(“1\n”);
else printf(“%d\n”, min+1);

``````}
return 0;
``````

}

### My code

``````#include <stdio.h>

int main(void) {
int test;
scanf("%d", &test);
while(test--){
int size;
scanf("%d", &size);
char arr[size];
scanf("%s", arr);
int counter1=0,counter0=0;
for(int i=0;i<size;i++){
if(arr[i]=='0') counter0++;
if(arr[i]=='1') counter1++;
}
int min=counter0;
if(min>counter1) min=counter1;
if(counter0==size) printf("0\n");
else if(counter1==size) printf("1\n");
else if(counter0==counter1) printf("%d\n", counter1);
else if(counter1==1) printf("1\n");
else printf("%d\n", min+1);

}
return 0;
}

``````

Problem Link: ZEROSTRING Problem - CodeChef

@rohanbhat
I have rectified it . U don’t need this much conditions .
I have made some things easier . Hope u will get the logic.

``````#include <stdio.h>

int main(void) {
int test;
scanf("%d", &test);
while(test--){
int size;
scanf("%d", &size);
char arr[size];
scanf("%s", arr);
int counter1=0,counter0=0;
for(int i=0;i<size;i++){
if(arr[i]=='0') counter0++;
if(arr[i]=='1') counter1++;
}
if(counter1<=counter0)
{
printf("%d\n",counter1);
}
else
{
printf("%d\n",counter0+1);
}
}
return 0;
}
``````