We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 68c9cd1 commit b05deebCopy full SHA for b05deeb
1 file changed
Java Subarray.java
@@ -0,0 +1,27 @@
1
+// https://www.facebook.com/abhi.sensharma/posts/1241788872853419
2
+// Subscribed by Abhishek Sharma
3
+
4
+import java.io.*;
5
+import java.util.*;
6
7
+public class Solution {
8
9
+ public static void main(String[] args) {
10
+ Scanner sc = new Scanner(System.in);
11
+ int n = sc.nextInt();
12
+ int [] arr = new int [n];
13
+ for(int i = 0; i < n; i ++) {
14
+ arr[i] = sc.nextInt();
15
+ }
16
17
+ int count = 0, sum = 0;
18
19
+ for(int j = i; j < n; j ++) {
20
+ sum += arr[j];
21
+ if(sum < 0) count ++;
22
23
+ sum = 0;
24
25
+ System.out.println(count);
26
27
+}
0 commit comments