You are viewing a single comment's thread. Return to all comments →
Hey! We did the same solution! This is what i did in Java:
public static long arrayManipulation(int n, int[][] queries) { long[] array = new long[n]; for(int[] query : queries) { array[query[0] - 1] += query[2]; if(query[1] < n) { array[query[1]] += (query[2] * -1); } } long max = 0; long currentVal = 0; for(int i = 0; i < n; i++) { currentVal += array[i]; if(currentVal > max) { max = currentVal; } } return max; }
public static long arrayManipulation(int n, int[][] queries) { long[] array = new long[n];
for(int[] query : queries) { array[query[0] - 1] += query[2]; if(query[1] < n) { array[query[1]] += (query[2] * -1); } } long max = 0; long currentVal = 0; for(int i = 0; i < n; i++) { currentVal += array[i]; if(currentVal > max) { max = currentVal; } } return max; }
I spent 2 days to come up with this solution, tho :( I feel so slow, i hope i can improve... I will !
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 →
Hey! We did the same solution! This is what i did in Java:
I spent 2 days to come up with this solution, tho :( I feel so slow, i hope i can improve... I will !