Hi guys,
i am trying to add two values at a specific index and places it back into an array, but the compiler is coming up with some Run time error… not sure if i am doing it correct.
also if any one can clarify please if array and arrayobject are the same things or there is any key difference between them.
appreciate your help
note: this is one of the data structure problem at,https://www.hackerrank.com/challenges/crush/problem
so basically, i have two arrays,
// new1 is array
new1=[0,0,0,0,0,0]
// queries is array object
1 2 100
2 5 100
3 4 100
so basically, from first queries the x=1 (start position), y=2 (end position), z=100, so adding value z from position x to y in new1 array, and this will happen three times as we got three items in the queries.
so the working will be like…
new1 =[0 100 100 0 0 0 ] // here adding 100 to position 1 to 2
new1= [ 0 100 200 100 100 100] // here adding 100 to position 2 to 5
new1 = [0 100 200 200 200 100] // here adding 100 to position 3 to 4
function arrayManipulation(n, queries) {
// n is the length of new array
let new1 = new Array(n).fill(0)
for( let i=0; i<n; n++){
let x =queries[i][0]
let y= queries[i][1]
for (x; x<y; x++){
let z =queries[0][2]
new1[i] = new1[i] + z
}
}
return new1
}