Pergunta de entrevista da empresa ReverbNation

Using a pen and paper(and over the phone) write a function that shows all permutations of a given string. Given the string 'abc' it should return 'abc', 'acb', 'bac', 'bca'... etc.

Respostas da entrevista

Sigiloso

21 de jun. de 2017

This isn't that big of a deal but this guy's garbage at helping you, he kept trying to shove in recursion where the solution I had was already doing the same thing. try to ignore his help. For the answer, just google 'permutation' + (some language) and it will show you what you need.

Sigiloso

1 de mar. de 2018

This is basically a classical backtracking question, wherein you follow three steps recursively namely: create, recurse, uncreate. So the base case for recursion is that the length of string being created equals to the given string length. Then the next part is iterating over the given string and if the string contains the current character then continue else add the character to the string and then recursively call the backtrackUtil function. And the uncreate step is to remove the character from the string which is at last position.