Pergunta de entrevista da empresa Box

algorithm for getting the number of anagrams.

Resposta da entrevista

Sigiloso

7 de mai. de 2012

This is simply the number of ways you can permute a string. Simply pass in a boolean array that determines which letter of the string have been used and which haven't: permuteStrings(String x, int currentIndex, boolean[] isUsed, char[] originalString) { if (currentIndex == originalString.length) { System.out.println(x); } else { for (int i = 0; i < originalString.length; i++) { if (isUsed[i]) { continue; } else { isUsed[i] = true; permuteStrings(new String(x.append(originalString[i])), currentIndex++, isUsed, originalString); isUsed[i] = false; } } } }

1