What are some practical uses of generating all permutations of a list, such as ['a', 'b', 'c'] ?
- by Jian Lin
I was asked by somebody in an interview for web front end job, to write a function that generates all permutation of a string, such as "abc" (or consider it ['a', 'b', 'c']).
so the expected result from the function, when given ['a', 'b', 'c'], is
abc
acb
bac
bca
cab
cba
Actually in my past 20 years of career, I have never needed to do something like that, especially when doing front end work for web programming.
What are some practical use of this problem nowadays, in web programming, front end or back end, I wonder?
As a side note, I kind of feel that expecting a result in 3 minutes might be "either he gets it or he doesn't", especially I was thinking of doing it by a procedural, non-recursive way at first. After the interview, I spent another 10 minutes and thought of how to do it using recursion, but expecting it to be solved within 3 minutes... may not be a good test of how qualified he is, especially for front end work.