• + 1 comment

    What is the issue with this code? It takes 3.3 seconds in Windows and 1.3 seconds in Mac but Hackerank shows runtime error for 10 mill n elements

    def arrayManipulation(n, queries):

    temp_arr = [0]*(n+1)
    
    for a,d,k in queries:
        temp_arr[a-1] += k
        temp_arr[d] -=k
    
    for i in range(1,n):
        temp_arr[i] += temp_arr[i-1] 
    
    return(max(temp_arr))
    
    • + 0 comments

      There is nothing wrong I can find. I believe it is correct. The runtime error may come from max(10 milliion length of array) which times out.