1 day ago · Tech · 0 comments

The challenge Given a word (a string of lowercase letters), return all its permutations in alphabetical order. Do not use built-in permutation functions. Examples: permutations("the"); // → [eht, eth, het, hte, teh, the] permutations("a"); // → [a] This puzzle is asked on Codewars and HackerRank Java tracks. Two parts trip people up: generating the permutations from scratch, and ordering them alphabetically. Solution 1: recursive, no built-ins The classic recursive approach. Each call removes one character, recurses on the rest, then prepends the removed character to every sub-result:

No comments yet. Log in to reply on the Fediverse. Comments will appear here.