Sollicitatievraag bij Wayfair

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

Antwoorden op sollicitatievragen

Anoniem

7 mrt 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.

Anoniem

13 mei 2019

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

Anoniem

13 mei 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; }