Sort by

recency

|

31 Discussions

|

  • + 1 comment
    def solve(y):
        V = 0
        n = len(y)
        result = []
    
        for num in y:
            count = sum(1 for other_num in y if other_num >= num)
            result.append(count)
    
        [V += (n+1)/ (result[i]+1) for i in range(n)]
        
        return ["%.2f" % V]
    
  • + 0 comments
    def solve(y):
        y, n  = sorted(y,reverse=True), len(y) 
        num_replicas, total = 0, 1
        factorial_i_minus_1 = 1
        
        for i in range(2,n+1):
            factorial_i_minus_1 *= i-1
            is_replica = y[i-1]==y[i-2]
            num_replicas = is_replica * (is_replica + num_replicas)
            total += i * total + factorial_i_minus_1 * (i - num_replicas)
            
        return ["{0:.2f}".format(total/factorial_i_minus_1/n)]
    
  • + 0 comments

    The editorial has the most inefficient solution to this problem. Three for loops--are you sure? This was my linear python3 solution (I tried to make it as readable as possible and in line with the vars defined in the problem's description):

    def solve(n, y):
        V = 0
        y.sort()
        for i in range(n):
            if i == 0 or (i > 0 and y[i] > y[i-1]): 
                k = n-i
                v_i = (n+1)/(k+1) 
            V += v_i
        return ["%.2f" % V]
    

    This also exercises Linearity of Expectation, but all it's doing is sorting the input array y then walking through it to sum up v_i. If there's a repeating value, it'll use the first instance of v_i for that value (since v_i will continue to decrease as i increases).

  • + 0 comments

    Error: Garbage collector could not allocate 16384 bytes of memory for major heap section.

    :/

  • + 0 comments

    for javascript function processData(input) { //Enter your code here var loopNum=input.split("\n")[0];

    var inpuJump=1;
    for(var i=0;i<loopNum;i++){
        var arrSize=parseInt(input.split("\n")[inpuJump]);
        var arr=input.split("\n")[inpuJump+1].split(" ");
    
        var sumArr=0;
        for(var j=0;j<arrSize;j++){
            sumArr+=(parseInt(arrSize)+1)/((parseInt(getLarger(arr,arr[j])))+1);
        }
     console.log(sumArr.toFixed(2));   
    
        inpuJump+=2;
    }
    
    function getLarger(arrt,curr){
        var count=0;
        for(var i=0;i<arrSize;i++){
            if(parseInt(arrt[i])>=curr) count++;
        }
        return count;
    }
    

    }