A puzzle page shows an n × n chess board. The player must place n queens so that no two share a row, a column, or a diagonal. Some squares are covered by ads and can't hold a queen; they are listed in blocked as [row, col] pairs.
Write countQueenLayouts(n, blocked) that returns how many valid layouts exist. Blocked squares don't block attacks; they only can't hold a queen.
Input: n = 4, blocked = [] Output: 2
A 4 × 4 board has two layouts: queens in columns 1, 3, 0, 2 or 2, 0, 3, 1, row by row.
Input: n = 4, blocked = [[0,1]] Output: 1
The ad at row 0, column 1 removes the first layout and leaves the other.
1 <= n <= 120 <= blocked.length <= n * n, so at most 144Run 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 #307 Queen Puzzle With Ad Slots. 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.