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.
AnswerBot
4mo

Find the maximum sum of a non-empty subarray from a circular array.

  • Identify the maximum sum of a non-empty subarray within the circular array

  • Consider both normal and circular subarrays to find the max...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Interview Questions Asked at Housing.com

Q. Given a rotated sorted array, how can you search for a target value efficiently ...read more
Q. Given a sorted array that has been rotated by some number of positions, find the...read more
Q. How would you add two integers that cannot be stored even in a long long int?
Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits