Sort by

recency

|

2462 Discussions

|

  • + 2 comments

    You can look at the queries as histograms so you've got a bunch of histograms and you want to combine them. Basically you don't want overlapping queries.

    A way to do this is to consider each index in the queries as a level transition. Doesn't matter if it's at the query start index or the end index. You can just make tuples of...( transition_index, level_change) A starting query index has positive level_change. An ending query index has a neg. level_change. Just track the sum level as you go

  • + 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
    
  • + 0 comments

    Think of keeping an array that save the delta of operation. Then add up the array to see which index is the peak (max). By this way, you can find the optimal solution

  • + 0 comments

    ?

  • + 0 comments

    Array manipulation involves modifying, adding, or removing elements in an array to structure data effectively. It’s essential for optimizing code performance, especially with large datasets. Techniques like slicing and mapping are widely used in programming. Learn more about related topics like how to activate Glo SIM.