Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
19 lines (18 loc) · 661 Bytes

File metadata and controls

19 lines (18 loc) · 661 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class maximum_subarray {
public static int max_contagious_subarray_sum(int[] arr){
int maximum_so_far=arr[0];
int maximum_ending_here=arr[0];
for(int i=1;i<arr.length;i++){
maximum_so_far=Math.max(arr[i], maximum_so_far+arr[i]);
if(maximum_so_far>maximum_ending_here){
maximum_ending_here=maximum_so_far;
}
}
return maximum_ending_here;
}
public static void main(String[] args) {
int[] arr= {-2, -3, 4, -1, -2, 1, 5, -3};
int max_cont_sub_sum=max_contagious_subarray_sum(arr);
System.out.println(max_cont_sub_sum);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.