import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class SetPacking {
public static int maxPackedSets(int[] items,
List<int[]> sets)
{
int maxSets = 0;
for (int[] set : sets) {
int numSets = 0;
for (int item : items) {
if (contains(set, item)) {
numSets++;
items = remove(items, item);
}
}
maxSets = Math.max(maxSets, numSets);
}
return maxSets;
}
public static boolean contains(int[] array, int value)
{
for (int element : array) {
if (element == value) {
return true;
}
}
return false;
}
public static int[] remove(int[] array, int value)
{
List<Integer> result = new ArrayList<>();
for (int element : array) {
if (element != value) {
result.add(element);
}
}
return result.stream().mapToInt(i -> i).toArray();
}
public static void main(String[] args)
{
int[] items = { 1, 2, 3, 4, 5, 6 };
List<int[]> sets = new ArrayList<>();
sets.add(new int[] { 1, 2, 3 });
sets.add(new int[] { 4, 5 });
sets.add(new int[] { 5, 6 });
sets.add(new int[] { 1, 4 });
int maxSets = maxPackedSets(items, sets);
System.out.println(
"Maximum number of sets that can be packed: "
+ maxSets);
}
}