-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaccenture_24.java
More file actions
32 lines (28 loc) · 890 Bytes
/
Copy pathaccenture_24.java
File metadata and controls
32 lines (28 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
Maximum Subarray Sum
Problem Description:
Given an array of integers, find the maximum subarray sum. A subarray is a contiguous subsequence of the array.
Explanation:
Given an array of integers, such as [-2, 1, -3, 4, -1, 2, 1, -5, 4], the algorithm should determine that the maximum subarray sum is 6 ([4, -1, 2, 1]).
*/
import java.util.*;
public class accenture_24 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
sc.close();
int max=Integer.MIN_VALUE;
int s;
for(int i=0;i<n;i++){
s=0;
for(int j=i;j<n;j++){
s+=a[j];
max=Math.max(max, s);
}
}
System.out.println(max);
}
}