• + 0 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));
        }        
    }