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.
Examples
Example 1
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.
Example 2
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.
Constraints
1≤n≤2000
0≤conflicts.length≤104
conflicts[i].length == 2
1≤a<b≤n
all conflict pairs are distinct
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up