Getting Wrong Answer

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

public static void main(String[] args) throws NumberFormatException, IOException {
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	int t=Integer.parseInt(br.readLine());
	while(t-->0) {
		int size=Integer.parseInt(br.readLine());
		int[] arr=new int[size];
		StringTokenizer st=new StringTokenizer(br.readLine());
		for (int i = 0; i < arr.length; i++) {
			arr[i]=Integer.parseInt(st.nextToken());
		}
		System.out.println(circularSubArraySum(arr));
	}
}

public static int circularSubArraySum(int[] arr) {
	int global_max=Integer.MIN_VALUE;
	for (int i = 0; i < arr.length; i++) {
		int current_max = arr[i];
		global_max = arr[i];
		for (int j = i + 1; j < arr.length + i; j++) {
			current_max = Math.max(arr[j % arr.length], current_max + arr[j % arr.length]);
			if(current_max>global_max) {
				global_max=current_max;
			}
		}
	}
	return global_max;
}

}

//I am getting wrongA answer msg whereas in ide i am geeting the correct ans

@ubaidshaikh9999,
Reviewing your code!

@ubaidshaikh9999,
For the input:
1
8
-1 40 -14 7 6 5 -4 -1

Correct Answer: 52
Your Answer: 44

For the input:
1
8
10 -3 -4 7 6 5 -4 -1
Correct Answer: 23
Your Answer: 21

Suggested Approach:

For finding the Maximum Contiguous sum we are using the kadane’s algorithm. But in the question the array is circular that means the maximum sum can be of elements which are a part of the wrapping or not. So,
There can be two cases for the maximum sum:
Case 1: The elements that contribute to the maximum sum are arranged such that no wrapping is there. Examples: {-10, 2, -1, 5}, {-2, 4, -1, 4, -1}. In this case, Kadane’s algorithm will produce the result.

Case 2: The elements which contribute to the maximum sum are arranged such that wrapping is there. Examples: {10, -12, 11}, {12, -5, 4, -8, 11}. In this case, we change wrapping to non-wrapping. Let us see how. Wrapping of contributing elements implies non wrapping of non contributing elements, so find out the sum of non contributing elements and subtract this sum from the total sum. To find out the sum of non contributing, invert sign of each element and then run Kadane’s algorithm. Our array is like a ring and we have to eliminate the maximum continuous negative that implies maximum continuous positive in the inverted arrays.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.