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.
Scanner scan = new Scanner(System.in);
int size = scan.nextInt();
int[] array = new int[size];
for(int i=0; i
for (int i=0; i <= j ; i++) {
a = 0;
for(int p = i; p < j ; p++) {
a += array[p];
}
if (a < 0) {
negativeSum++;
}}
}
System.out.println(negativeSum);
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 →
It's my solution:
Scanner scan = new Scanner(System.in); int size = scan.nextInt(); int[] array = new int[size]; for(int i=0; i for (int i=0; i <= j ; i++) {
a = 0; for(int p = i; p < j ; p++) {
a += array[p]; } if (a < 0) { negativeSum++; }} } System.out.println(negativeSum);