You are viewing a single comment's thread. Return to all comments →
Java O(n + m)
public static long arrayManipulation(int n, List<List<Integer>> queries) { long[] arr = new long[n + 1]; for (List<Integer> query : queries) { int a = query.get(0); int b = query.get(1); int k = query.get(2); arr[a - 1] += k; arr[b] -= k; } long max = 0; long sum = 0; for (long num : arr) { sum += num; max = Math.max(max, sum); } 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 →
Java O(n + m)