Sort by

recency

|

632 Discussions

|

  • + 0 comments

    my code:

    import java.io.; import java.util.;

    public class Solution {

    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;
    }
    

    }

  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        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 scan= new Scanner(System.in);
            int n=scan.nextInt();
            int[] a= new int[n];
            for(int i=0;i<n;i++){
                a[i]=scan.nextInt();
            }
            int count=0;
            for(int k=0;k<n;k++){
                for(int i=0,j=i+k;i<n && j<n;i++,j=i+k){
                    int sum=0;
                    for(int x=i;x<=j;x++){
                        sum+=a[x];
                    }
                    count=sum<0? count+1:count;
            }}
            System.out.println(count);
        }
    }
    
  • + 0 comments

    java

    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
           Scanner in=new Scanner(System.in);
           int n=in.nextInt();
           int[] arr=new int[n];
           for(int i=0;i<n;i++){
               arr[i]=in.nextInt();
           }
           int count=0;
           for(int i=0;i<n;i++){
               int sum=0;
               for(int j=i;j<n;j++){
                   sum=sum+arr[j];
                   if(sum<0){
                       count++;
                   }
               }
           }
           System.out.println(count);
           
        }
    }
    
  • + 0 comments

    not able to understand this question,can any one clarify it

  • + 0 comments

    Scanner sc=new Scanner(System.in); int jum=sc.nextInt(); int jumtot=0; int count=0; int[] arrJum=new int[jum]; String test=""; for (int i = 0; i < jum; i++) { int val=sc.nextInt(); arrJum[i]=val;

        }
    
    
        for (int i = 0; i < arrJum.length; i++) {
            for (int j = i; j < arrJum.length; j++) {
                for (int j2 = i; j2 <= j; j2++) {
                    jumtot+=arrJum[j2];
    
                    test=test+String.valueOf(arrJum[j2]);
                }
                if(jumtot<0) count++;
                test="";
                jumtot=0;
    
            }
        }
    
        System.out.println(count);