• + 0 comments
    It passes 9 test cases out of 16 test cases and remaining 7 test cases it says time limit exceeded......What to do??
    
    def arrayManipulation(n, q):
        # Write your code here
        temp=[]
        for i in range(0,n):
            temp.append(0)
        for j in range(len(q)):
            a,b,k=q[j][0],q[j][1],q[j][2]
            for z in range(a-1,b):
                temp[z]=temp[z]+k
        return max(temp)
    		
    	
    		UPDATED USED PREFIX SUM AND DIFFERENCE ARRAY TO OPTIMIZE THE CODE
    		
    		def arrayManipulation(n, q):
        # Write your code here
        temp=[]
        for i in range(0,n):
            temp.append(0)
        for j in range(len(q)):
            a,b,k=q[j][0],q[j][1],q[j][2]
            temp[a-1]=temp[a-1]+k
            if b<n:   # if b<len(temp):
                temp[b]=temp[b]-k
        sum=0
        maxi=0
        for z in range(len(temp)):
            sum=sum+temp[z]
            maxi=max(sum,maxi)
        return maxi