Sort by

recency

|

3186 Discussions

|

  • + 0 comments

    Does anyone have the R solution?

  • + 0 comments

    for java 8+

    List<Integer> arrp=arrz,arrn=arrz;
            int size=arrz.size();
            double n=arrn.stream().filter((i)->i<0).count(),
            z=arrz.stream().filter((i)->i==0).count(),
            p=arrp.stream().filter((i)->i>0).count();
            DecimalFormat df = new DecimalFormat("0.000000");
            System.out.println(df.format(p/size));
            System.out.println(df.format(n/size));
            System.out.println(df.format(z/size));``
    
  • + 0 comments

    JavaScript solution

    function plusMinus(arr) {
      const long = arr.length
      
      let totalPositives = 0
      let totalNegatives = 0
      let totalZero = 0
    
      arr.forEach(e => {
        if (e > 0) totalPositives++
        if (e < 0) totalNegatives++
        if (e === 0) totalZero++
      })
    
      const calculateRatio = (total, n) => console.log((total / n).toFixed(6))
    
      calculateRatio(totalPositives, long)
      calculateRatio(totalNegatives, long)
      calculateRatio(totalZero, long)
    }
    
  • + 0 comments

    **here is my python solution **

    def plusMinus(arr):

    n = len(arr)
    
    positive_count = sum(1 for x in arr if x > 0)
    negative_count = sum(1 for x in arr if x < 0)
    zero_count = sum(1 for x in arr if x == 0)
    
    positive_ratio = positive_count / n
    negative_ratio = negative_count / n
    zero_ratio = zero_count / n
    
    print(f"{positive_ratio:.6f}")
    print(f"{negative_ratio:.6f}")
    print(f"{zero_ratio:.6f}")
    
  • + 0 comments
    void plusMinus(vector<int> arr) {
        int cnt[3] = {0,0,0};
        float s = 1.0f/arr.size();
        for (auto x : arr)
            cnt[(x > 0) - (x < 0) + 1]++;
    
        cout << fixed;
        cout << s * cnt[2] << endl;
        cout << s * cnt[0] << endl;
        cout << s * cnt[1] << endl;
    }