function solution(arr, query) {
query.forEach((q, idx) => {
if (idx % 2 === 0) {
arr.splice(q+1)
} else {
arr.splice(0, q)
}
})
return arr;
}
function solution(arr, query) {
let s = 0;
let e = query.length - 1;
for (let i=0; i<query.length; i++) {
if (i%2==0) e = s + query[i];
else s += query[i];
}
const answer = arr.slice(s, e);
return answer.length ? answer : [-1];
}