This repository was archived by the owner on May 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
54 lines (38 loc) · 1.37 KB
/
Solution.java
File metadata and controls
54 lines (38 loc) · 1.37 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.io.*;
import java.util.*;
import java.util.stream.Stream;
public class Solution {
public static void main(String[] args) throws IOException {
/*
* Enter your code here. Read input from STDIN. Print output to STDOUT. Your
* class should be named Solution.
*/
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bufferedReader.readLine().trim()); // length of the main array
int[] arr = new int[n];
String a = bufferedReader.readLine();
bufferedReader.close();
String[] vals = a.split(" ");
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(vals[i]);
// System.out.println(arr[i]);
}
int negCounter = 0;
for (int i = 0; i < arr.length; i++) {
for (int j = i; j < arr.length; j++) {
int sum = 0;
// For loop to print subarray elements
for (int k = i; k <= j; k++) {
sum += arr[k];
// System.out.print(arr[k] + " ");
// System.out.println("");
}
if (sum < 0) {
negCounter++;
}
}
}
System.out.println(negCounter);
// For loop for end index
}
}