Can you tell whats wrong with my code?

if(a[n-1]>0)
		{
			i=0;
		}

if a[n-1] is less than zero, then i is set to zero.
it will run in an infinite loop.

Correct Approach :

first case can be calculated by Kadane.
for second ques, if you multiply the array by -1 and then do kadane it will give min subarray.

You have not considered the case of intersection of a prefix and suffix.

@Madeshi-Chinmay-2159857244260221
Case 2 is the intersection of prefix and suffix.

Well the correct logic is described nicely by abhinandan …please see that

Hello @abhinandankainth1999 @Madeshi-Chinmay-2159857244260221 ,
I wrote this code again but still its not passing any testcases whereas I am getting the correct answer. Considered both cases as you suggested.