We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] array1= new int[n];
for(int i=0;i<n;i++){
array1[i]=sc.nextInt();
}
int count=0;
for(int j=0;j<n;j++){
int sum=0;
for(int k=j;k<n;k++){
sum=array1[k]+sum;
if(sum<0){
count++;
}
}
}
System.out.println(count);
}
Java Subarray
You are viewing a single comment's thread. Return to all comments →
CAN I OPTIMISE THIS SOLUTION?? (o(N)???)
public class Solution {
}