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.
Here, an easiest way to understand in ruby, at least for me.
def arrayManipulation(n, queries)
arr = Array.new(n + 1, 0)
queries.each do |q|
arr[q.first - 1] += q.last
arr[q[1]] -= q.last
end
tmp = 0
max = 0
arr.each do |n|
tmp += n
max = tmp if tmp > max
end
max
end
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 →
Here, an easiest way to understand in ruby, at least for me.