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.
structCompressedArray{vararray=[Int:Int]()mutatingfuncsetData(value:Int,startPoint:Int,endPoint:Int){ifletval=array[startPoint]{array[startPoint]=val+value}else{array[startPoint]=value}letep=endPoint+1ifletval=array[ep]{array[ep]=val-value}else{array[ep]=-value}}funcGetMax()->Int{varmaxVal=0varval=0forkeyinarray.keys.sorted(){ifletvalue=array[key]{val+=value}maxVal=max(maxVal,val)}returnmaxVal}}funcarrayManipulation(n:Int,queries:[[Int]])->Int{// Write your code herevarcompressedArray=CompressedArray()forqueryinqueries{compressedArray.setData(value:query[2],startPoint:query[0],endPoint:query[1])}returncompressedArray.GetMax()}
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 →
Just store the data in a dictionary as below: