We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
max=list1[0]
for j in range(1,n):
list1[j]=list1[j]+list1[j-1]
if max
here list1 is prefix sum arraywhy did my code failed few test cases?here's my entire code :
def arrayManipulation(n, queries):
list1=[0]*(n+1)
for i in range(len(queries)):
list1[queries[i][0]-1]+=queries[i][2]
list1[queries[i][1]]+=-queries[i][2]
"""prefix sum"""
max=list1[0]
for j in range(1,n):
list1[j]=list1[j]+list1[j-1]
if max<list1[j]:
max=list1[j]
return(max)
if max<list1[j]:
max=list1[j]
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
I replaced this part of your code :
max = x = 0 for i in list: x=x+i; if(max
by this:
max=list1[0] for j in range(1,n): list1[j]=list1[j]+list1[j-1] if max
here list1 is prefix sum array why did my code failed few test cases? here's my entire code : def arrayManipulation(n, queries): list1=[0]*(n+1)