We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Is there a reason all the solutions posted above are written inside main() and not the provided function arrayManipulation() ? Or did hackerrank just change this over the past few years for readability?
// Complete the arrayManipulation function below.staticlongarrayManipulation(intn,int[][]queries){// initialize array with 0's of size nlongarr[]=newlong[n];// each successive element contains the difference between itself and previous elementfor(inti=0;i<queries.length;i++){// when checking query, subtract 1 from both a and b since 0 indexed arrayinta=queries[i][0]-1;intb=queries[i][1]-1;intk=queries[i][2];arr[a]+=k;if(b+1<n){arr[b+1]-=k;}}// track highest val seen so far as we golongmax=Long.MIN_VALUE;for(inti=1;i<arr.length;i++){arr[i]+=arr[i-1];max=Math.max(arr[i],max);}returnmax;}
Cookie support is required to access HackerRank
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 →
Is there a reason all the solutions posted above are written inside main() and not the provided function arrayManipulation() ? Or did hackerrank just change this over the past few years for readability?