A settings page shows a row of toggles. The design rule says two toggles next to each other can't both be on. An admin has locked some toggles, and the rest are free.
pattern describes the row: "1" is locked on, "0" is locked off, and "?" is free. Write completeTogglePatterns(pattern) that returns every way to set the free toggles so the whole row follows the rule, as strings of "0" and "1".
Return the strings sorted ascending. If no setting works (for example, two locked toggles next to each other are both on), return [].
Input: pattern = "???" Output: ["000","001","010","100","101"]
Every 3-toggle row with no two neighbors on, from smallest to largest.
Input: pattern = "1?0?" Output: ["1000","1001"]
The second toggle must be off because the first is on. The last one can be either.
1 <= pattern.length <= 12pattern only contains 0, 1, and ?.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).
I'm here to help with #287 Complete the Toggle Row. 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.