1- Given an array of integers, positive and negative. find an interval in that array, whose elements constitutes the maximum sum
Anónimo
Complete solution covering all -1 and returning the interval indexes: int [] arr = {-123,-3,-9,-222,-44,-1,-66}; int currSeqLeft = 0; int currSeqRight = 0; int curr = arr[0]; int largestSeqLeft = 0; int largestSeqRight = 0; int largest = arr[0]; for (int i = 1; i = 0 ){ curr += arr[i]; currSeqRight = i; } if (curr > largest) { largest = curr; largestSeqLeft = currSeqLeft; largestSeqRight = currSeqRight; } } System.out.println(largestSeqLeft + "," + largestSeqRight);