• + 0 comments

    Here's the same solution in swift in case anyone needs it :).

    func arrayManipulation(n: Int, queries: [[Int]]) -> Int { var sums = Int: Int for query in queries { sums[query[0]] = (sums[query[0]] ?? 0) + query[2] sums[query[1] + 1] = (sums[query[1] + 1] ?? 0) - query[2] }

    var currentmax = 0
    var sum = 0
    sums.sorted{ `$0.0 < $`1.0 }.
        compactMap{ `$0.1; sum += $`0.1; currentmax = sum > currentmax ? sum : currentmax}
    return currentmax
    

    }