I am getting this error. Plz look into my code. Link: https://ide.codingblocks.com/s/87168
I am getting a run-time error
Hi Himalaya
First of all the time complexity of your code is bad. Dont you think you should try kadanne’s algorithm?
Second Please consider the constraints as well,while creating your array:
1 <= N <= 100000
1 <= t <= 20
-100000000 <= A[i] <= 100000000
Hi Himalaya, try Kadane’s algorithm, its time complexity is O(n).
Its tough to explain it here completely. So I’m dropping a link for you here -> https://youtu.be/86CQq3pKSUw
I have used Kadane’s algo. Now what is the problem. Still getting the same error.
Hi
Your code has certain small mistakes:
Consider doing something like
maximum=a[0];
sum=a[0];
for(i=1;i<n;i++){
sum=max(a[i],sum+a[i]);
maximum=max(maximum,sum);
}
In your case:
4
-1 -2 -3 -4 would give 0 but ideally answer should be -1