You're given N integer arrays. Each array can have different size and contains unique values. However same integers can be found in different arrays.
The goal is to partition those arrays into K groups such that:
- Arrays grouped together don't share any integer
- I want to minimize the number of groups
Example:
Input: [[1, 2, 3], [2, 4, 5], [6, 7, 8], [4, 6, 10]]
Suboptimal Solution using 3 groups:
- group 1: [[1, 2, 3], [6, 7, 8]]
- group 2: [[2, 4, 5]]
- group 3: [[4, 6, 10]]
Optimal Solution using 2 groups:
- group 1: [[1, 2, 3], [4, 6, 10]]
- group 2: [[2, 4, 5], [6, 7, 8]]
Any idea on how to solve this effectively?