Possible Duplicate:
Combination of List<List<int>>
I have multiple Lists, could be 2 or 3 up to 10 lists, with multiple
values in them. Now what I need to do is to get a combination of all
of them.
For example, if I have 3 lists with the following values:
- List 1: 3, 5, 7
- List 2: 3, 5, 6
- List 3: 2, 9
I would get these combinations
- 3,3,2
- 3,3,9
- 3,5,2
Etc..
Now the problem is I cannot do this easily because I do not know how many lists I have, therefore determine how many loops I need.
You could probably make that a lot easier, but this is what I had in mind just now:
If I’m not completely wrong, this should be
O(Nm)withmbeing the number of lists andNthe number of permutations (product of the lengths of allmlists).