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.
I spent the night managing linked lists, and a headache! Your solution is so simple and so clear. Here is my small addition:
// credit amansbhandari for his crystal clear solution in C++// The beauty of JavaScript Object/Set/Arrays is an improvement// space = O(k) time = O(k)functionarrayManipulation(n,queries){letarro={}leta,b,k,i,x=0,imax=0for(i=0;i<queries.length;i++){a=queries[i][0]b=queries[i][1]k=queries[i][2]arro[a]=(arro[a])?arro[a]+k:karro[b+1]=(arro[b+1])?arro[b+1]-k:0-k}for(iinarro){x+=arro[i]if(x>imax)imax=x}returnimax}
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 →
I spent the night managing linked lists, and a headache! Your solution is so simple and so clear. Here is my small addition: