Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Max Sum in Circular Array
00:00
5 left

Max Sum in Circular Array

HardPython

Problem

Max sum in a circular array (where subarrays can wrap around)

Asked in the Round 2 DSA + Java stage. Followed by discussion on Java fundamentals.

Implement max_circular_subarray_sum(nums). The input is a non-empty list of integers. Return the largest sum of a non-empty contiguous subarray, allowing the subarray to wrap from the last element to the first.

Example: [5, -3, 5] returns 10; [-3, -2, -1] returns -1.

Function signature: def max_circular_subarray_sum(nums):

Constraints

  • 1 <= nums.length <= 1000
  • -10^4 <= nums[i] <= 10^4
  • The selected subarray must contain at least one element

Function Signature

def max_circular_subarray_sum(nums):
Interviewer

Your question is Max Sum in Circular Array. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.