A support team splits n people, numbered 0 to n - 1, into a day shift and a night shift. Each pair in conflicts must be on different shifts. Nobody likes night shifts.
Write fewestNightShift(n, conflicts) that returns the smallest possible number of people on the night shift in a valid split, or -1 if no valid split exists. A shift may be empty.
Input: n = 5, conflicts = [[0,1],[0,2],[3,4]] Output: 2
Put 0 on nights and 1 and 2 on days: 1 person. For the pair 3 and 4, one of them must work nights: 1 more. The total is 2.
Input: n = 3, conflicts = [[0,1],[1,2],[2,0]] Output: -1
A triangle of conflicts can't be split into two shifts.
1 <= n <= 100000 <= conflicts.length <= 500000 <= a, b < n, a !== bRun 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).
I'm here to help with #453 Fewest People on the Night Shift. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.