You are viewing a single comment's thread. Return to all comments →
public static long arrayManipulation(int n, List<List<Integer>> queries) { long[] array = new long[n+2]; for(int i = 0; i < queries.size(); i++) { long numberToAdd = queries.get(i).get(2); int startIndex = queries.get(i).get(0); int endIndex = queries.get(i).get(1); array[startIndex] += numberToAdd; array[endIndex+1] -= numberToAdd; } long max = 0; for(int i = 1; i < array.length; i++) { array[i] += array[i-1]; max = Math.max(array[i],max); } return max; }
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →