I was trying to solve a data structure question from Hackerrank and i could not figure it out. Actually, i could not understand exact logic lying under problem.Below is a link to question question.
Asked
Active
Viewed 156 times
-1
-
Problem deal with number ranges, so look at interval/range data structures – MBo Feb 07 '17 at 04:21
-
Sir, I tried to solve that but I could not figured out by my way . I think there is another logic on this problem. – Ozan Apaydın Feb 07 '17 at 06:37
-
You have to show your efforts to get a chance for any answer. – MBo Feb 07 '17 at 07:34
1 Answers
0
This is not optmized, so will not pass all tests cases for python (10s timenout), but you can have an idea.
n, m = map(int, raw_input().strip().split(' '))
numbers = []
for i in range(m+1):
numbers.append(0)
for i in range(m):
a , b , k = map(int, raw_input().strip().split(' '))
for j in range(b - a + 1):
numbers[a + j -1] = numbers[a + j - 1] + k
print(max(numbers))

Samuel Teixeira
- 326
- 2
- 9