Question:
Given n sets of choices: (1, 2, 3), (a, b, c), (i, ii, iii).
You pick one element from each set of choices. Generate all possible pickings.
http://www.glassdoor.com/Interview/Given-n-sets-of-choices-1-2-3-2-3-4-4-5-You-pick-one-element-from-each-set-of-choices-Generate-all-possibl-QTN_218899.htm
private List
> generateAllPickings(String[][] pool){ List
> result = new ArrayList<>(); help(pool, 0, new ArrayList (), result); return result;}private void help(String[][] pool, int group, List cur, List
> result){ if (cur.size() == pool.length) { result.add(new ArrayList (cur)); } if (group >= pool.length) { return; } // Now we are looking at pool[group], put each elements into the cur for (int i = 0 ; i < pool[group].length ; i ++) { cur.add(pool[group][i]); help(pool, group + 1, cur, result); cur.remove(cur.size() - 1); }}