4 ms·
One I got recently - and blanked on - write a function to generate all the permutations of a string. Recursion preferred.
by goodgoblin 17y ago
One I got recently - and blanked on - write a function to generate all the permutations of a string. Recursion preferred.
- bshep 17y agoQuick and Dirty(probably better ways to do it): def permute(string, prefix = ''): if len(string) == 1: print prefix + string return for x in range(0, len(string)): new_prefix = prefix + string[x] unused_chars = string[0:x] + string[x+1:] permute(unused_chars, new_prefix)
- dodger1 17y agoThis same website has a solution for the permutation of a string. http://www.mytechinterviews.com/permutations-of-a-string http://www.mytechinterviews.com/permutations-of-a-string