• + 0 comments

    Only consider the query indices.

    def arrayManipulation(n, queries):
        # Write your code here
        sweepline = {}
    
        # O(N)
        for (start, end, value) in queries:
            sweepline[start] = sweepline.get(start, 0) + value
            sweepline[end + 1] = sweepline.get(end + 1, 0) - value
    
        maxnum = float("-inf")
        curr = 0 
        
        for index in sorted(sweepline.keys()):
            curr += sweepline[index]
            maxnum = max(maxnum, curr)
        
        return maxnum