int Solution::solve(vector<int> &A, int B) {
int size = static_cast<int>(A.size());
int max = 0;
// printf("%d ",size);
// printf("%d %d ",A[0],A[size-1]);
int temp = 0, t2 = 0;
for (int i = -1; i < B; i++) {
if (i != -1)
temp += A[i];
t2 = temp;
for (int j = size - 1; j > (size - B + i); j--)
t2 += A[j];
if (t2 > max)
max = t2;
}
return max;
}
When I run this code the value of max returned is 0 when the print statements are commented. When I use the print statements, the value returned is correct. Can anyone help me to understand as to why this is happening? OR if there is a workaround the problem? (I don't want to printing any output through its function). Using printf with empty quotations or NULL does not seem to resolve the issue either. Any help is appreciated.