## Amazon Interview Question for SDE-2s

Country: United States

Comment hidden because of low score. Click to expand.
1
of 1 vote

``````int zc=0,l=0,max=0;
for(int i=0;i<nums.length;i++){

if(nums[i]==0)
zc++;
while(zc>k){
if(nums[l++]==0)
zc--;
}
max=Math.max(max,i-l+1);
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````int zi=-1,l=-1,max=0;
for(int i=0;i<nums.length;i++){
if(nums[i]==0) {
if(!l<0)
max=Math.max(i-l);
l=zi+1;
zi=i;
}
}``````

``````int zc=0,l=0,max=0;
for(int i=0;i<nums.length;i++){
if(nums[i]==0) {
zc++;
}
while(zc>k){
if(nums[l++]==0)
zc--;
}
max=Math.max(max,i-l+1);
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````int zc=0,l=0,max=0;
for(int i=0;i<nums.length;i++){

if(nums[i]==0)
zc++;
while(zc>k){
if(nums[l++]==0)
zc--;
}
max=Math.max(max,i-l+1);
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

iterate a given array while keeping track of max consecutive 1s so far and counting running consecutive 1s. Compare max so far and running num.

iterate the input array by counting the number of zeros.

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.