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.
can the same be written like this:
def arrayManipulation(n, queries):
arr_n=[0]*n
for i in range(len(queries)):
n1=queries[i][0]
n2=queries[i][1]
for j in range(n1-1,n2):
arr_n[j]=arr_n[j]+queries[i][2]
return max(arr_n)
This is giving me a tiemout error while submitting.
can u assist here?
yeah,at the beginning, l got the same problem as well. This algorithm's complexity could be o(n). Try to learn something about prefix sum array.I hope this can help.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
can the same be written like this: def arrayManipulation(n, queries): arr_n=[0]*n for i in range(len(queries)): n1=queries[i][0] n2=queries[i][1] for j in range(n1-1,n2): arr_n[j]=arr_n[j]+queries[i][2] return max(arr_n) This is giving me a tiemout error while submitting. can u assist here?
yeah,at the beginning, l got the same problem as well. This algorithm's complexity could be o(n). Try to learn something about prefix sum array.I hope this can help.