A build configurator has n optional features, numbered 0 to n - 1. Some pairs can't be enabled together; they are listed in conflicts as [a, b].
Write countValidSets(n, conflicts) that returns how many sets of features (including the empty set) contain no conflicting pair.
n can be 20, so there are over a million sets: check each one in O(1) on average.
Input: n = 3, conflicts = [[0,1]] Output: 6
Of the 8 sets, only {0, 1} and {0, 1, 2} contain the conflict.
Input: n = 2, conflicts = [] Output: 4
No conflicts, so all 2^2 = 4 sets are valid.
1 <= n <= 200 <= conflicts.length <= 190a !== b, no pair listed twiceRun tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #676 Conflict-Free Feature Sets. 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.