Loading...
You are given n items labeled 1 to n and an array conflicts, where conflicts[i] = [a, b] means items a and b must not be placed in the same group.
Return true if all n items can be divided into two groups (of any sizes, including empty) so that no conflicting pair shares a group, and false otherwise.
Input: n = 4, conflicts = [[1, 2], [1, 3], [2, 4]]
Output: true
Explanation: One valid split is {1, 4} and {2, 3}: every conflicting pair is
separated.
Input: n = 3, conflicts = [[1, 2], [1, 3], [2, 3]]
Output: false
Explanation: The three items conflict pairwise, so any two of them placed
together violate a conflict; three groups would be needed.
n ≤2000conflicts.length ≤104conflicts[i].length == 2nClick "Run" to test with sample cases or "Submit" to run all tests.