0

I need to get all the combination of an array. From the shortest combo (1 letter) to the longest combinations (|number of letters|) without duplication

For example:

ArrayList<String> array = new ArrayList<String>();
array.add("a"); 
array.add("d"); 
array.add("e");
IterationWithoutDuplication(array);

public void IterationWithoutDuplication(array){
  //some kind of a loop/recursion
  printCurrentCombo();
  //do some other work on the specific combo
}

Output should be:

a
d
e
ad
ae
da
de
ea
ed
ade
aed
dae
dea
ead
eda

Notice how it goes first on:

  • 1 letter combinations; then
  • 2 letters combinations; then
  • 3 letters combinations; then
  • ..
  • |array size| letters combinations

But all the combinations are unique and doesnt contain the same letter more then once.

Of course I dont wish just to print it, but rather do some work - the question is how to scan an array this way efficient.

4

0 回答 0