Wayfair interview question

Write a code that show all possible permutation from a given String.

Interview Answers

Anonymous

7 Mar 2014

The answer is available on programmerinterview.com, relatively easy if you have learned the answer before going to interview. But quite difficult to find a solution on the spot.

Anonymous

13 May 2019

function swap(arr, indA, indB){ const temp=arr[indA]; arr[indA]=arr[indB]; arr[indB]=temp; return arr; } function allPerms(str){ if (str.length===1) return str; const perm=[...str]; const perms=[]; for (let i=0; i0;j--){ perms.push([...swap(perm,j-1,j)].join('')); } } return perms; }

Anonymous

13 May 2019

I solved it by myself. Took me an hour. Idk if this is the best solution though