You are viewing a single comment's thread. Return to all comments →
Hi, thanks for the wonderful explanation. Can you please check where I am wrong in this java code which I feel is similar to the one you posted.
public static long arrayManipulation(int n, List> queries) {
long[] baseArr = new long[n+1]; long maxSum = 0; if(queries == null || queries.size() ==0){ return 0; } for(List<Integer> query : queries){ int start = query.get(0)-1; int end = query.get(1) - 1; baseArr[start]+= query.get(2); baseArr[end+1]-= query.get(2); } int sum=0; for(long item : baseArr){ sum+=item; maxSum = Math.max(sum,maxSum); } return maxSum; }
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 →
Hi, thanks for the wonderful explanation. Can you please check where I am wrong in this java code which I feel is similar to the one you posted.
public static long arrayManipulation(int n, List> queries) {