# Help with bulbs cook off

I dont know why mi code for bulbs is wrong answer if it has the same logic than other codes i’ve seen. Can anyone help me?

Blockquote
import java.io.;
import java.util.
;
import java.lang.*;

class BULBS{
public static void main(String[] args)throws java.lang.Exception{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i = 1; i <= t; i++){
int N = sc.nextInt(); int K = sc.nextInt(); sc.nextLine();
String s = sc.nextLine();
ArrayList gz = new ArrayList();
int c = 0; boolean iz = false; int cz = 0;
int co = 0; int zerozleft = 0;
for(int j = 0; j < N; j++){
if(s.charAt(j) == ‘1’){
co++;
if(iz && co != 1){
iz = false;
}else{
zerozleft = c;
c = 0;
iz = false;
}
}else{
iz = true;
c++; cz++;
}
}
int zerozrigth = 0;
if(iz)
zerozrigth = c;
Collections.sort(gz);
int ans = deletezeroz(gz, K, cz, zerozleft, zerozrigth);
System.out.println(ans);
}
}

``````public static int deletezeroz(ArrayList<Integer> gz, int K, int cz, int zerozleft, int zerozrigth){
if(K == 0 || cz == 0){
return cz;
}else{
if(K == 1 && (zerozleft != 0 || zerozrigth != 0)){
int max = Math.max(zerozleft, zerozrigth);
return cz-max;
}else if(K == 1){
return cz;
}else{
if(zerozleft >= gz.get(gz.size()-1) || zerozrigth >= gz.get(gz.size()-1)){
if(zerozleft >= zerozrigth){
cz -= zerozleft;
zerozleft = 0;
K -= 1;
return deletezeroz(gz, K, cz, zerozleft, zerozrigth);
}else{
cz -= zerozrigth;
zerozrigth = 0;
K -= 1;
return deletezeroz(gz, K, cz, zerozleft, zerozrigth);
}
}else if(zerozleft + zerozrigth >= gz.get(gz.size()-1)){
cz -= zerozrigth + zerozleft;
zerozrigth = 0; zerozleft = 0;
K -= 2;
return deletezeroz(gz, K, cz, zerozleft, zerozrigth);
}else{
cz -= gz.get(gz.size()-1);
K -= 2;
gz.remove(gz.size()-1);
return deletezeroz(gz, K, cz, zerozleft, zerozrigth);
}
}
}
}
``````

}

Blockquote

Sorry for the code, here is the link
https://www.codechef.com/viewsolution/38080065