Geeksforgeeks

Timer is Running

Associated Course(s):
Geeks Classes
Geeks Classes DSA- Tutorials

Given an array **arr[]** of **N** integers arranged in a **circular** fashion. Your task is to find the **maximum contigious subarray sum**.

**Input:**

First line of input contains a single integer **T **which denotes the number of test cases. First line of each test case contains a single integer **N **which denotes the total number of elements. Second line of each test case contains N space separated integers denoting the elements of the array.

**Output:**

For each test case print the maximum sum obtained by adding the consecutive elements.

**Constraints:**

1 <= T <= 101

1 <= N <= 10^{6}

-10^{6 }<= Arr[i] <= 10^{6}

**Example:**

**Input:**

3

7

8 -8 9 -9 10 -11 12

8

10 -3 -4 7 6 5 -4 -1

8

-1 40 -14 7 6 5 -4 -1

**Output:**

22

23

52

**Explanation:
Testcase 1: **Starting from last element of the array, i.e, 12, and moving in circular fashion, we have max subarray as 12, 8, -8, 9, -9, 10, which gives maximum sum as 22.

Author: harsh.agarwal0

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

jainshubham52535 | 529 |

Pathak1899 | 436 |

yashdip123 | 380 |

kirtidee18 | 377 |

jots62 | 351 |

kirtidee18 | 1057 |

ykaushik | 752 |

aggarwalvatsal5 | 741 |

harbilassingh | 576 |

pmr_3689 | 570 |

blackshadows | 5456 |

Ibrahim Nash | 5450 |

akhayrutdinov | 5111 |

mb1973 | 4976 |

Quandray | 4827 |

Login to report an issue on this page.