Array Manipulation

Challenge 📝

You are given an array of n elements, initialized to 0. You are also given a list of m queries, where each query is represented by a triple (a, b, k) and denotes that you should add k to each element in the subarray arr[a...b].

Write a function arrayManipulation(n, queries) that returns the maximum value in the array after performing all the queries.

Examples:

const n = 5;
const queries = [[1, 2, 100], [2, 5, 100], [3, 4, 100]];
console.log(arrayManipulation(n, queries)); // Output: 200

// In the example above, the array arr starts as [0, 0, 0, 0, 0].
// After the first query, arr becomes [100, 100, 0, 0, 0].
// After the second query, arr becomes [100, 200, 100, 100, 100].
// After the third query, arr becomes [100, 200, 200, 200, 100],
// and the maximum value in the array is 200.

function arrayManipulation(n, queries) {
}
Test Cases
Console Logs
JS Errors
Run Code!
flag