Power Set

n x 2^n, n x 2^n
function powerset(arr) {
let answer = [[]];
for (const n of arr) {
const temp = [];
for (const el of answer) {
const next = [...el, n];
temp.push(next);
}
answer.push(...temp);
}
return answer;
}
// Do not edit the line below.
exports.powerset = powerset;simpler
PreviousPhone Number Mnemonics β can use word and index to create each case without concatenationNextPermutations -
Last updated