• + 1 comment
    public static long arrayManipulation(int n, List<List<Integer>> queries) {
        // Write your code here
            long[] res = new long[n+2];
            long max = 0;
            for(int i=0; i<queries.size(); i++){
                int a = queries.get(i).get(0);
                int b = queries.get(i).get(1);
                int k = queries.get(i).get(2);
    
                res[a] = res[a] + k;
                res[b+1] = res[b+1] - k;
    
            }
            for(int i=1; i<=n; i++){
                res[i] = res[i] + res[i-1];
                max = Math.max(res[i], max);
            }
            return max;
            
        }