00:00

Problem Statement

Input/Output Examples

Visual Explanation

Both Kadane passes run in the same loop. The all-negative case needs a guard: there, total minus minimum would mean taking no elements at all, which is not allowed.

Approaches

The circular Kadane method is linear. The brute force tries every start and length.

Java Solutions

Each tab is a complete program that runs on Java 17 or later. Both programs print the same output for the same inputs.

Complexity Analysis

Here n is the number of elements. The Kadane version reads each value once; the brute force considers n² circular subarrays.

Interview Tips and Recommended Approach

  • Explain the two cases. Non-wrapping uses plain Kadane; wrapping is total minus a middle part.
  • Guard the all-negative case. Otherwise the answer becomes 0, an empty subarray.
  • Do not double the array. Concatenating it and running Kadane can use an element twice.
  • Compute everything in one pass to keep the code short.

Recommended Approach: Kadane Max and Min

Why: it reduces the circular problem to two Kadane runs and a subtraction, all in one linear pass with constant memory.