Skip to the code
cf.
+10 XP

#451 Split Testers Into Two Groups

easy

An A/B test needs to put each of n testers, numbered 0 to n - 1, into group A or group B. Some pairs of testers share a household, and the pairs in conflicts must end up in different groups so they don't compare notes.

Write canSplit(n, conflicts) that returns true if every tester can be put in a group so that no conflicting pair is in the same group, and false otherwise.

Example 1

Input: n = 4, conflicts = [[0,1],[1,2],[2,3],[3,0]]
Output: true

Put 0 and 2 in group A and 1 and 3 in group B.

Example 2

Input: n = 3, conflicts = [[0,1],[1,2],[2,0]]
Output: false

In a triangle, two of the three testers must share a group.

Constraints

  • 1 <= n <= 10000
  • 0 <= conflicts.length <= 50000
  • 0 <= a, b < n, a !== b
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).