You are on page 1of 1

int max_no_of_words = 0;

int jump = 1;
int start = 0;
int end = 0;
for (int i=0; i<a.length; i=i+jump){
jump = 1;
start = i;
int kx = a[i];
int no_of_words = 1;
if (kx<=k){
if (no_of_words>max_no_of_words){
max_no_of_words = no_of_words;
}
}
else if (kx>k){
continue;
}
for (int j=i+1; j<a.length; j++){
kx = kx + a[j];
no_of_words = no_of_words+1;
if (kx<=k){
if (no_of_words>max_no_of_words){
max_no_of_words = no_of_words;
}
}
else if (kx > k){

for (int l = i; l<j; l++){


kx = kx - a[l];
no_of_words = no_of_words-1;
if (kx<=k){
jump = l-i+1;
if (no_of_words>max_no_of_words){
max_no_of_words = no_of_words;
}
break;
}
}
break;
}
}
}

You might also like