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 algoCrush():
try:
listSize, opsCount = map(int, raw_input().split())
except:
return None
#constraint 1 and 2
if not all([listSize >=3, listSize <= 10**7, opsCount >= 1, opsCount <= 2*10**5]):
return None
crushList = [0]*listSize
for _ in range(opsCount):
try:
start, end, addnum = map(int, raw_input().split())
except:
return None
#constraint 3 and 4
if not all([start >= 1, start <= end, end <= listSize, addnum >= 0, addnum <= 10**9]):
return None
crushList[start-1] += addnum
if end <= (listSize -1):
crushList[end] -= addnum
prev = high = 0
for i in range(listSize):
prev += crushList[i]
if high < prev:
high = prev
print high
algoCrush()
For instance, when list size less than 3, it should not return any thing.
2 3
1 2 3
1 2 3
1 2 3
9 -----> should have failed.
Likewise, when there are strings in numbers.
2 3
1 2 3
1 2 3
1 2 str
Traceback (most recent call last):
File "a.py", line 4, in <module>
a, b, k = [int(n) for n in raw_input().split() ]
ValueError: invalid literal for int() with base 10: 'str'
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 →
Same logic (thanks!) with constraits addressed.