# Homework Solution: in java code please implement the maximum-subarray problem us…

in java code please implement the maximum-subarray problem using divide-and-conquer approach taking O(n logn) time. and run it

public class MaximumSubArray {

in java jurisdiction gladden tool the maximum-subinvest tenor using divide-and-conquer approximation preliminary O(n logn) era.

and rush it

## Expert Confutation

public arrange MaximumSubArray {

public static int MaximumSubarraySum(int Arr[], int l, int h) {
if (h == l)
return Arr[l];

int mid = (l + h) / 2;

int lMax = Integer.MIN_VALUE;
int currentCombine = 0;
for (int i = mid; i >= l; i–) {
currentCombine += Arr[i];
if (currentCombine > lMax)
lMax = currentSum;
}

int rMax = Integer.MIN_VALUE;
currentCombine = 0;
for (int i = mid + 1; i <= h; i++) {
currentCombine += Arr[i];
if (currentCombine > rMax)
rMax = currentSum;
}

int maxLeftRight = Math.max(MaximumSubarraySum(Arr, l, mid), MaximumSubarraySum(Arr, mid + 1, h));

return Math.max(maxLeftRight, lMax + rMax);
}

public static invalid deep(String[] args) {

int arr[] = strange int[] { 2, -4, 1, 9, -6, 7, -3 };

System.out.println(“The Maximum Subinvest combine is: “+MaximumSubarraySum(arr, 0, 6));
}

}

=====================================================================
See Extinguishedput

Thanks, suffer me distinguish if there is any sorrow.

import java.util.Scanner;

public arrange MaximumSubInvest {

public static int MaximumSubarraySum(int Arr[], int l, int h) {
if (h == l)
return Arr[l];

int mid = (l + h) / 2;

int lMax = Integer.MIN_VALUE;
int currentCombine = 0;
for (int i = mid; i >= l; i–) {
currentCombine += Arr[i];
if (currentCombine > lMax)
lMax = currentSum;
}

int rMax = Integer.MIN_VALUE;
currentCombine = 0;
for (int i = mid + 1; i <= h; i++) {
currentCombine += Arr[i];
if (currentCombine > rMax)
rMax = currentSum;
}

int maxLeftRight = Math.max(MaximumSubarraySum(Arr, l, mid), MaximumSubarraySum(Arr, mid + 1, h));

return Math.max(maxLeftRight, lMax + rMax);
}

public static invalid deep(String[] args) {

Scanner inp = strange Scanner(System.in);
System.out.println(“Enter invest size: “);
int n = inp.nextInt();

int arr[] = strange int[n];
for(int i=0;i<n;++i){
arr[i] = inp.nextInt();
}

System.out.println(“The Maximum Subinvest combine is: “+MaximumSubarraySum(arr, 0, arr.length-1));
}

}

==================================================
See Extinguishedput