0% completed
what is the advantage of deque here in js solution? I did the same general thing...
Jacques
May 28, 2022
what is the advantage of deque here in js solution? I did the same general thing but kept my result as an array of arrays that was replaced each time i finished adding an element to each. function test(distinct) { let output = [[]]; distinct.forEach(el => { const newOutput = [] output.forEach(ar => { const possiblePlaces = ar.length + 1 for (let i = 0; i < possiblePlaces; i++) { const newArr = [] for (let j = 0; j < i; j++) { newArr.push(ar[j]) } newArr.push(el) for (let j = i; j < ar.length; j++) { newArr.push(ar[j]) } newOutput.push(newArr) } }) output = newOutput }) return output }
0
0
Comments
J 3 years ago
Deque allows for insertion of elements at the deque's start (index 0) in O(1) time.
J 3 years ago
Can't edit my previous comment but deque allow for O(1) time element insertions and removals at both the deque's start and end (at index 0 and index N - 1 respectively).
On this page