forked from codehouseindia/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathJava Subarray.java
More file actions
27 lines (23 loc) · 673 Bytes
/
Java Subarray.java
File metadata and controls
27 lines (23 loc) · 673 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
// https://www.facebook.com/abhi.sensharma/posts/1241788872853419
// Subscribed by Abhishek Sharma
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int [] arr = new int [n];
for(int i = 0; i < n; i ++) {
arr[i] = sc.nextInt();
}
int count = 0, sum = 0;
for(int i = 0; i < n; i ++) {
for(int j = i; j < n; j ++) {
sum += arr[j];
if(sum < 0) count ++;
}
sum = 0;
}
System.out.println(count);
}
}