Created
January 8, 2022 11:39
-
-
Save nhnam/73b91379a0b56462915c4f268ebe992a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function arrayManipulation(n, queries) { | |
// Write your code here | |
var arr = Array(n + 1).fill(0); | |
var max = 0; | |
var x = 0; | |
for(var query of queries) { | |
const [a, b, k] = query; | |
arr[a] += k; | |
if(b+1 <= n) { | |
arr[b+1] -= k; | |
} | |
} | |
for(var i = 1; i <= n; i++) { | |
x = x + arr[i]; | |
if(x > max) { | |
max = x; | |
} | |
} | |
return max; | |
} | |
const queries = [[1, 2, 100], [2, 5, 100], [3, 4, 100]]; | |
let res = arrayManipulation(5, queries); | |
res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment