admin@onlinelearningcenter.in (+91) 7 999 01 02 03

Find largest sum of contiguous subarray within a given array of integers.

Swapnil M
4 Posts

 

Write a program to find contiguous subarray within a given array of integers which has the largest sum.

Example :

Input:int[] A = {1, 2, -3, -4, 0, 6, 7, 8, 9}

Output: The largest sum of contiguous sub-array: 30 

Above answer if 30 because sum of 0 + 6 + 7 + 8 +9 is 30

 

Input:int[] A = {12, 2, -34, 1, 10, -18, 9}

Output: The largest sum of contiguous sub-array: 12

Above is answer is 14. Because sum of no other contihuous subarray is greater than 14.

Published By : Swapnil M
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Comments

Jquery Comments Plugin