• + 0 comments

    Same Solution in Scala

    def arrayManipulation(n: Int, queries: Array[Array[Int]]): Long = {

    val arr = Array.ofDim[Long](n + 1)
    
    for (q <- queries) {
      arr(q(0)) = arr(q(0)) + q(2)
      if (q((1)) + 1 != arr.size)
        arr(q(1) + 1) = arr(q(1) + 1) - q(2)
    
    }
    
    
    for (i <- 1 to arr.length - 1) {
      arr(i) = arr(i) + arr(i - 1)
    }
    arr.max
    

    }