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.
var arr = Array(repeating: 0, count: n+1)
for query in queries {
let a = query[0] - 1
let b = query[1]
let k = query[2]
arr[a] += k
arr[b] -= k
}
var largestValue = Int.min
var sum = 0
for n in arr {
sum += n
largestValue = max(sum, largestValue)
}
return largestValue
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 →
Updated version: