Welcome back to week eleven of the weekly programming contests! If you are new to the contest or need a refresher don’t forget to read up on the rules and information Posted Here
This weeks challenge is to write a method (you can call it anything you want) that takes in a String and returns an array containing all the possible permutations of the given String, without repeats, so “bob” should only appear once! Additionally, no element in the array can be null
You can assume all letters are lowercase.
Examples:
perm("") -> [""]
perm(“h”) -> [“h”]
perm(“hi”) -> [“hi”, “ih”]
perm(“bob”) -> [“bob”, “bbo”, “obb”]
perm(“fun”) -> [“fun”, “fnu”, “ufn”, “unf”, “nfu”, “nuf”]
perm(“bye”) -> [“bye”, “bey”, “ybe”, “yeb”, “eby”, “eyb”]
perm(“poop”) -> [“poop”, “popo”, “ppoo”, “opop”, “oppo”, “oopp”]
perm(“stop”) -> [“stop”, “stpo”, “sotp”, “sopt”, “spto”, “spot”, “tsop”, “tspo”, “tosp”, “tops”, “tpso”, “tpos”, “ostp”, “ospt”, “otsp”, “otps”, “opst”, “opts”, “psto”, “psot”, “ptso”, “ptos”, “post”, “pots”]
Imports are allowed for this challenge!
Challenge Closes: Sunday 1/17/15
Good luck!