Summing same index values in 2D arrays in javascript
The problem is, that you create an array of length n for each operation (in the input array), and then sum them by calling reduce on the result and after that you finally find the maximum of that resulting array. But you only need one initial array to sum up in, and you can find the maximum in the same operation - here in a rather verbose form:

function arrayManipulation(n, arr) {
  var res = [];
  var max = 0;

  for (var i = 0; i &lt; arr.length; i++) {
    for (var j = 0; j &lt; n; j++) {
      if (i === 0) {
        res.push(j &gt;= arr[i][0] - 1 &amp;&amp; j &lt;= arr[i][1] - 1 ? arr[i][2] : 0);
      }
      else {
        res[j] += j &gt;= arr[i][0] &amp;&amp; j &lt;= arr[i][1] ? arr[i][2] : 0;
      }
      max = Math.max(max, res[j]);
    }
  }
  return max;
}


which can be narrowed down to this more succinct form:

function arrayManipulation(n, arr) {
  var res = [];
  var max = Number.MIN_VALUE;

  for (var i = 0; i &lt; arr.length; i++) {
    for (var j = arr[i][0]; j &lt;= arr[i][1]; j++) {
      res[j] = (res[j] || 0) + arr[i][2];
      max = Math.max(max, res[j]);
    }
  }
  return max;
}


Here is used, that it is only needed to loop through the intervals of the array that is actually manipulated by each operation in the input array. So for instance in the example operations, it is for the first operation only necessary to add 3 to the values in places from 1 to 5 inclusive. 



Update

Building on the idea from the comment by weegee a modification of my solution above could handle that:

function arrayManipulation(n, arr) {
  arr = arr.sort((a, b) =&gt; a[0] &lt; b[0] ? -1 : a[0] === b[0] ? 0 : 1);
  var max = Number.MIN_VALUE;

  for (var i = 0; i &lt; arr.length; i++) {
    var sum = arr[i][2];
    for (var j = i + 1; j &lt; arr.length; j++) {
      if (arr[j][0] &lt;= arr[i][1])
        sum += arr[j][2];
      else
        break;
    }
    max = Math.max(sum, max);
  }

  return max;
}


First the operations are sorted according to their start position (first element in the sub array), and then the operations are iterated and summed up as long as there is an overlap from operation to operation. Finally the current sum is compared to the existing maximum sum in max.