title: Divide & Conquer algorithm for finding sum of positive numbers in circularly sorted array
body: <p>I am trying to find the <strong>O(N) solution with Divide &amp; Conquer</strong> for the next problem:</p>
  
  <p>Given a <strong>circularly sorted array</strong>, I need the <strong>sum of the positive numbers</strong> on it. i.e:</p>
  
  <pre><code>If the array is: {-2, 0, 3, 4, 11, 13, -23, -15, -8}
  
  Then the algorithm should return 31.
  </code></pre>
  
  <p>I think I'm close to it with the following code, but it's weirdly returning -17 and I cannot find the problem debugging:</p>
  
  <pre><code>public class Main {
  
  private static final int[] TEST_VECTOR = new int[]{-2, 0, 3, 4, 11, 13, -23, -15, -8};
  
  public static int sumPositives2(int[] vector) {
      return maximumSum(vector,0, vector.length - 1);
  }
  
  // Function to find Maximum subarray sum using
  // divide and conquer
  public static int maximumSum(int[] A, int left, int right)
  {
      // If array contains only one element
      if (right == left) {
          return A[left];
      }
  
      // Find middle element of the array
      int mid = (left + right) / 2;
  
      // Find maximum subarray sum for the left subarray
      // including the middle element
      int leftMax = Integer.MIN_VALUE;
      int sum = 0;
      for (int i = mid; i &gt;= left; i--)
      {
          if(A[i] &gt; 0) {
              sum += A[i];
          }
      }
  
      // Find maximum subarray sum for the right subarray
      // excluding the middle element
      int rightMax = Integer.MIN_VALUE;
      sum = 0;    // reset sum to 0
      for (int i = mid + 1; i &lt;= right; i++)
      {
          if(A[i] &gt; 0) {
              sum += A[i];
          }
      }
  
      // Recursively find the maximum subarray sum for left
      // subarray and right subarray and tale maximum
      int maxLeftRight = maximumSum(A, left, mid) +
              maximumSum(A, mid + 1, right);
  
      // return maximum of the three
      return maxLeftRight + leftMax + rightMax;
  }
  
  public static void main(String[] args)
  {
      System.out.println("The Maximum sum of the subarray is " +
              maximumSum(TEST_VECTOR, 0, TEST_VECTOR.length - 1));//Should be 31
  
  }
  }
  </code></pre>
  
  <p>Edit: <strong>Would this solution be O(N)?</strong></p>
  
  <p>Thank you for your time.</p>