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.
func arrayManipulation(n: Int, queries: [[Int]]) -> Int {
var arr = Array(repeating: 0, count: n+1)
queries.forEach{
let a = $0[0]
let b = $0[1]
let k = $0[2]
arr[a-1] += k
arr[b] -= k
}
let reducedArr = arr.reduce(into: (0,0), { result, number in
result.0 += number
result.1 = max(result.1, result.0)
})
return reducedArr.1
}
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 solution in Swift
func arrayManipulation(n: Int, queries: [[Int]]) -> Int {
}