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.
Itpasses9testcasesoutof16testcasesandremaining7testcasesitsaystimelimitexceeded......Whattodo??defarrayManipulation(n,q):# Write your code heretemp=[]foriinrange(0,n):temp.append(0)forjinrange(len(q)):a,b,k=q[j][0],q[j][1],q[j][2]forzinrange(a-1,b):temp[z]=temp[z]+kreturnmax(temp)UPDATEDUSEDPREFIXSUMANDDIFFERENCEARRAYTOOPTIMIZETHECODEdefarrayManipulation(n,q):# Write your code heretemp=[]foriinrange(0,n):temp.append(0)forjinrange(len(q)):a,b,k=q[j][0],q[j][1],q[j][2]temp[a-1]=temp[a-1]+kifb<n:#ifb<len(temp):temp[b]=temp[b]-ksum=0maxi=0forzinrange(len(temp)):sum=sum+temp[z]maxi=max(sum,maxi)returnmaxi
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 →