All permutations in Java
Java interview exercise on Algorithms & recursion, difficulty 3 of 3. Solve it in the editor beside a worked example; the tests run the moment you do.
Write permutations(s) that returns every ordering of the characters of s (all distinct) as a list of strings, in the order a depth-first search produces when it tries the remaining characters left to right: "abc" → [abc, acb, bac, bca, cab, cba]. The empty string has one permutation, "".
Each exercise pairs a worked example with a twin problem to solve in a real editor; the tests run the moment you do. Progress is saved in your browser, and in your account if you sign in.