• + 1 comment

    Same idea in java. Thank you for posting this by the way , helped immensely!

    static long arrayManipulation(int n, int[][] queries) {
        long[] diff = new long[n+2];
        for(int[] query : queries){
            diff[query[0]]+=query[2]; //a,b,k
            diff[query[1]+1]-=query[2];
        }
        long  max =0;
        long current=0; 
        for(long i : diff){
            current+=i;
            if (current >  max )
                max = current;
        }
        return max;
    }