Maximum Sum Circular Subarray Problem Statement

Find the maximum possible sum of a non-empty subarray from a given circular array/list ARR containing N integers.

Explanation:

The array is circular, meaning the end of the list connects back to the beginning. A circular subarray may only include each element once.

Input:

The first line contains an integer 'T' indicating the number of test cases.
For each test case:
The first line contains an integer 'N', the number of elements in the array 'ARR'.
The second line contains 'N' space-separated integers representing the array 'ARR'.

Output:

Print the maximum possible sum of a non-empty subarray of 'ARR' for each test case, one per line.

Example:

Input:
ARR = [1, 2, -3, -4, 5]
Output:
8

Explanation: The subarray [5, 1, 2] forms the maximum sum of 8, as the array is circular.

Constraints:

  • 1 ≤ T ≤ 100
  • 1 ≤ N ≤ 105
  • -105 ≤ ARR[i] ≤ 105
  • Time Limit: 1 sec
Note:
The output for each test case continues automatically. You just need to implement the function.
Be the first one to answer
Add answer anonymously...
Housing.com Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter