function Permutation(str) {
// write code here
const res = [],
path = [],
used = {};
const arr = str.split("");
if (arr.length === 0) return [];
helper();
return Array.from(new Set(res));
function helper() {
if (path.length === str.length) {
res.push(path.slice().join(""));
return;
}
for (let i = 0; i < arr.length; i++) {
if (!used[i]) {
used[i] = true;
path.push(arr[i]);
helper();
path.pop();
used[i] = false;
}
}
}
}
module.exports = {
Permutation: Permutation,
};