We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi, I copied approximately same code as yours in C. But it is not giving output. Please can you help in finding the problem.
int* maxset(int* A, int n1, int *len1) { int i=0, maxm =0, count =0, start =0, end =-1, fstart=-1, fend=-1; long long int sum =0, maxsum=0; //make a array as well while (i<n1) { if (A[i] >= 0) { sum = sum+A[i]; count++; end++; } if (sum > maxsum) { maxsum = sum; fstart = start; fend = end; } else if (sum==maxsum && count>maxm){ maxm = count; fstart = start; fend = end; } if (A[i] < 0){ count =0; start = i+1; end = i; sum =0; } i++; } if (fstart != -1 && fend != -1){ int res[fend-fstart]; res[0] = 0; for (i=fstart;i<fend;i++){ // res[i] = A[i]; } return res; } return -1; }
The text was updated successfully, but these errors were encountered:
if (fstart != -1 && fend != -1) { int res[fend - fstart + 1]; int index = 0; for (i = fstart; i <= fend; i++) { res[index] = A[i]; index++; } return res; }
Sorry, something went wrong.
No branches or pull requests
Hi,
I copied approximately same code as yours in C. But it is not giving output. Please can you help in finding the problem.
int* maxset(int* A, int n1, int *len1) {
int i=0, maxm =0, count =0, start =0, end =-1, fstart=-1, fend=-1;
long long int sum =0, maxsum=0;
//make a array as well
while (i<n1) {
if (A[i] >= 0) {
sum = sum+A[i];
count++;
end++;
}
if (sum > maxsum) {
maxsum = sum;
fstart = start;
fend = end;
}
else if (sum==maxsum && count>maxm){
maxm = count;
fstart = start;
fend = end;
}
if (A[i] < 0){
count =0;
start = i+1;
end = i;
sum =0;
}
i++;
}
if (fstart != -1 && fend != -1){
int res[fend-fstart];
res[0] = 0;
for (i=fstart;i<fend;i++){
// res[i] = A[i];
}
return res;
}
return -1;
}
The text was updated successfully, but these errors were encountered: