1 year ago
#234623
jack
N groups have a list of numbers that it can pick. Determine if all groups will be able to choose a number if one group chooses number i
Say that there is a group, each with numbers that it can pick.
Group 1: [1, 2, 3, 4],
Group 2: [2, 3, 4],
Group 3: [2, 3, 4],
Group 4: [4]
Say that it initially Group 4 chooses 4 in its list. Now, other groups can't use a 4. One possible arrangement is group 1 chooses the 1, group 3 chooses the 2, and group 2 chooses the 3. However, if group 1 initially chooses 4, there is no valid arrangement, since the only number group 4 can use is 4. Since 4 was used by group 1, group 4 can't choose any numbers, and thus not every group can choose a number. Return true or false if given that group N chooses a number i that they can pick, all the rest of the groups can choose a number. Is there an efficient O(n) or O(n^2) algorithm?
My solution attempt/thoughts:
Originally, I thought that maybe converting this into a directed graph representation and determining if there is a way for all nodes to be traversed to from another node. However, this would mean there are loops involved, and also this is polynomial.
algorithm
optimization
graph
match
bipartite
0 Answers
Your Answer