You are viewing a single comment's thread. Return to all comments →
public static Set<Integer> stones(int num, int first, int second) { Set<Integer> finalset = new TreeSet<>(); helper(num, first, second, finalset); helper(num, second, first, finalset); return finalset; } private static void helper(int num, int first, int second, Set<Integer> finalset) { int d = num-1; int x = d; int y = 0; for(int i=1; i<=d; i++) { List<Integer> lst = new ArrayList<>(); for(int j = 0; j < x; j++) { lst.add(lst.size()>0 ? first + lst.get(lst.size()-1) : first); } for(int j = 0; j< y; j++) { lst.add(lst.size()>0 ? second + lst.get(lst.size()-1) : second); } x--; y++; finalset.add(lst.get(lst.size()-1)); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Manasa and Stones
You are viewing a single comment's thread. Return to all comments →