Sort by

recency

|

3213 Discussions

|

  • + 0 comments

    Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-plus-minus-problem-solution.html

  • + 0 comments
    int positive = 0, negative = 0, zero = 0;
    
    for (int i = 0; i < arr_count; i++) {
        if (arr[i] > 0) {
            positive++;
        } else if (arr[i] < 0) {
            negative++;
        } else {
            zero++;
        }
    }
    printf("%.6f\n", (float)pos / arr_count);
    printf("%.6f\n", (float)neg / arr_count);
    printf("%.6f\n", (float)zero / arr_count);
    

    }

  • + 0 comments

    TypeScript

    function plusMinus(arr: number[]): void {
        const n = arr.length;
        let [positive, negative, zero] = [0, 0, 0];
    
        arr.forEach(num => {
            if (num > 0) positive++;
            else if (num < 0) negative++;
            else zero++;
        });
    
        console.log((positive / n).toFixed(6));
        console.log((negative / n).toFixed(6));
        console.log((zero / n).toFixed(6));
    }
    
    const input = require("fs").readFileSync(0, 'utf-8').split('\n');
    const n = parseInt(input[0]);
    const arr = input[1].split(' ').map(Number);
    
    plusMinus(arr);
    
  • + 0 comments

    TypeScript

    
    
  • + 0 comments

    def isNegative(x): return x < 0

    def isPositive(x): return x > 0

    def isZero(x): return x == 0

    def plusMinus(arr): # Write your code here negative = float(len(list(filter(isNegative, arr))) / len(arr)) positive = float(len(list(filter(isPositive, arr))) / len(arr)) zero = float(len(list(filter(isZero, arr))) / len(arr))

                                                                    print(str(positive) + '\n' + str(negative) + '\n' + str(zero))