Skip to content

Instantly share code, notes, and snippets.

@inodaf
Created January 18, 2021 16:44
Show Gist options
  • Save inodaf/e7b51f225d853e9e4508ec4856c6eeed to your computer and use it in GitHub Desktop.
Save inodaf/e7b51f225d853e9e4508ec4856c6eeed to your computer and use it in GitHub Desktop.
function max(target: Array<Number>): Number {
const reducer = (greatest, current) => current > greatest ? current : greatest
return target.reduce(reducer)
}
function crush(length, queries) {
const zeroes = Array(length).fill(0)
for (let i = 0; i < queries.length; i++) {
const [a, b, k] = queries[i];
for (let j = a - 1; j < b; j++) {
zeroes[j] += k
}
}
return zeroes
}
const queries = [[1,2,100], [2,5,100], [3,4,100]]
max(crush(5, queries)) // 200
function getRange(target, start, end) {
const range = []
for (let i = start - 1; i < end; i++) {
range.push(target[i])
}
return range
}
getRange(Array(5).fill(0), 1, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment