Skip to content

Instantly share code, notes, and snippets.

@bendozy
Created June 24, 2022 09:46
Show Gist options
  • Save bendozy/c6ab1aae558877da137a2c5963810ccd to your computer and use it in GitHub Desktop.
Save bendozy/c6ab1aae558877da137a2c5963810ccd to your computer and use it in GitHub Desktop.
Array Manipulation - Hackerrank
function arrayManipulation(n: number, queries: number[][]): number {
const data: number[] = Array(n).fill(0);
let maxValue: number = Number.MIN_VALUE;
let sum: number = 0
queries.forEach(([startIndex, endIndex, fillValue]) => {
data[startIndex - 1] += fillValue
if(data[endIndex] !== undefined) data[endIndex] -= fillValue
})
data.forEach((value) => {
sum += value
maxValue = Math.max(sum, maxValue)
})
return maxValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment