We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
function arrayManipulation(n: number, queries: number[][]): number {
let arr: number[] = Array(n+1).fill(0)
let max = 0;
queries.forEach((el)=>{
let a = el[0]
let b = el[1]
let k = el[2]
arr[a-1] = arr[a-1] + k
arr[b] = arr[b] - k
})
let sum = 0;
for (let i = 0; i< arr.length-1; i++){
sum = sum + arr[i]
sum > max ? max = sum : null
}
return max
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
function arrayManipulation(n: number, queries: number[][]): number {
}