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) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = scan.nextInt();
}
System.out.println(count(arr));
scan.close();
}
public static int count(int[] arr) {
int dem = 0;
for(int i =0; i<arr.length; i++){
for(int j = i; j<arr.length; j++){
int sum =0;
for(int m = i; m<=j; m++){
sum+=arr[m];
}
if(sum < 0){
dem++;
}
}
}
return dem;
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Subarray
You are viewing a single comment's thread. Return to all comments →
my code:
import java.io.; import java.util.;
public class Solution {
}