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.
importjava.io.*;importjava.util.*;publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannerscan=newScanner(System.in);intn=scan.nextInt();int[]a=newint[n];for(inti=0;i<n;i++){a[i]=scan.nextInt();}intcount=0;for(intk=0;k<n;k++){for(inti=0,j=i+k;i<n&&j<n;i++,j=i+k){intsum=0;for(intx=i;x<=j;x++){sum+=a[x];}count=sum<0?count+1:count;}}System.out.println(count);}}
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 →