Problem · Array

Find Largest Sum Contiguous Subarray

Learn this problem
EasyCisco logoCiscoINTERNOA
See Cisco hiring insights

Problem statement

You are given a list of integers (both positive and negative). Find the continuous sequence of integers with the largest sum.

Write an algorithm to find the largest sum of the continuous sequence from the given list.

Input

The first line of input consists of an integer - inputArr_size, representing the size of the list (N). The next line consists of N space-separated integers representing the elements of the list.

Output

Print an integer representing the largest sum of the continuous sequence from the given list.

Function

findLargestSumContiguousSubarray(inputArr: int[]) → int

Examples

Example 1

inputArr = [2, -8, 3, -2, 4, -10]return = 5

The given list is (2, -8, 3, -2, 4, -10), and we take (3, -2, 4) as the continuous sequence for getting the largest sum. The sum is 3+ (-2) +4, which is 5.

Constraints

--

More Cisco problems

drafts saved locally
public int findLargestSumContiguousSubarray(int[] inputArr) {
  // write your code here
}
inputArr[2, -8, 3, -2, 4, -10]
expected5
checking account