• + 0 comments

    Hi, I've seen many use the prefix sum algorithm to solve this problem, before looking into it I was trying with this:

        arr = [0] * n
        for start, end, value in queries:
            sub_arr = arr[start - 1:end]
            add_arr = [value] * len(sub_arr)
            sub_arr = [a+b for a,b in zip(sub_arr, add_arr)]
            arr = arr[0:start - 1] + sub_arr + arr[end:]
        return max(arr)
    

    but it says the max number is not the expected one, at the end, seems like with sum prefix we can recreate the same array I generate each query so I cannot see why the returned max value is not correct, if anyone has an answer, I would be glad to reaad i it, thanks.