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.
def boxops(box, oplist):
for op in oplist:
if len(op)==4:
num, l, r, a = op
if num == 1:box = [item+a if ind in range(l, r+1) else item for ind, item in enumerate(box)]
else:
box = [math.floor(item/a) if ind in range(l,r+1) else item for ind, item in enumerate(box)]
else:
num, l, r = op
if num == 3:
print(min(box[l:r+1]))
else:
print(sum(box[l:r+1]))
if __name__ == '__main__':
nq = input().split()
n = int(nq[0])
q = int(nq[1])
box = list(map(int, input().rstrip().split()))
oplist = []
for _ in range(q):
oplist.append(list(map(int, input().strip().split())))
boxops(box, oplist)
mine timesout after testcase 4 too.. any idea how to solve it?
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
Box Operations
You are viewing a single comment's thread. Return to all comments →
The code below solves the first four test cases but timeout for the rest. Any idea about improving the speed?
mine timesout after testcase 4 too.. any idea how to solve it?