Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Created by rg3 on 10/17/17.
*/
import java.util.ArrayList;
public class NoOfStories {
static int small=1;
static int large=2;
public static ArrayList<ArrayList<String>> combinations(int stories) {
ArrayList<ArrayList<String>> result = new ArrayList<>();
//start from an empty list
result.add(new ArrayList<>());
for (int i = 0; i < stories; i++) {
//list of list in current iteration of the array stories
ArrayList<ArrayList<String>> current = new ArrayList<>();
for (ArrayList<String> l : result) {
// # of locations to insert is largest index + 1
for (int j = 0; j < l.size()+1; j++) {
// + add stories[i] to different locations
if (j/large ==0) {
l.add(j, "small");
} else {
l.add(j, "large");
}
//l.add(j, i);
ArrayList<String> temp = new ArrayList<>(l);
current.add(temp);
//System.out.println(temp);
// - remove stories[i] add
l.remove(j);
}
}
result = new ArrayList<ArrayList<String>>(current);
}
return result; }
public static void main(String[] args) {
System.out.println(combinations(3));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.