Sort by

recency

|

198 Discussions

|

  • + 0 comments
    def solve(n, operations):
        count=0
        for operation in operations:
                count+=operation[2] *(operation[1]-operation[0]+1)
        return math.floor(count/n)
    
  • + 1 comment

    For C++ solution change the return type of solve function to long long and also type of result variable in main function from where solve is being called.

  • + 0 comments

    Java int array [ ] = new int[n]; for(List operation: operations){ int a = operation.get[0]-1; int b = operation.get[1]-1; int k = operation.get[2]; for(int i=a; i<=b; i++){ array[i]+= k; } }

                    int sum =0;
                                        for(int i=0 i<n; i++){
                    sum+= array[i];
    }
    return Math.round(sum/n);
    
    
    
    
    
    }
    
  • + 0 comments
    python3
    
    def solve(n, operations):
        # Write your code here
        total = 0
        for i in operations:
            indices = i[1]-i[0]+1
            total += i[2]*indices
            
        return math.floor(total/n)   
        
            
    
  • + 0 comments

    Python:

    def solve(n, operations):
        return int(sum((op[1]-op[0]+1)*op[2] for op in operations)/n)