DSA-125 · FOCUSED PRACTICE
N-Queens
Advanced · Java 21 · Version 1 · editorial draft
Java reference and baseline verified on JDK 21: 32 deterministic checks. Learner drafts are not executed.
Understand the problem
Return every arrangement of n queens on an n×n board with no two queens sharing a row, column, or diagonal. Represent each board as n Strings containing Q and dot characters.
- n must be in 0..10; otherwise both methods throw IllegalArgumentException. The enforced upper bound controls exhaustive search and materialized output. n=0 returns one empty board, [[]], while n=2 and n=3 return no boards.
- solveNQueens returns boards in lexicographic order of their row-by-row queen-column vectors, trying columns left to right. This is not a claim about lexicographic ordering of the rendered dot/Q Strings. Rotations and reflections are separate valid boards; no symmetry quotient is applied.
- Return a fresh mutable outer list and an independent mutable row-list container for every board, including the empty board. Strings are immutable and may safely share values. Every nonempty row String has exactly n characters with one Q, and all remaining characters are dots. Calls share no mutable result containers.
Examples
Input:
n=4
Output:[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]The column vectors [1,3,0,2] and [2,0,3,1] are the two distinct arrangements.
Input:
n=2
Output:[]A separate column forces a diagonal attack.
Input:
n=0
Output:[[]]One empty arrangement exists; no negative-length diagonal array is allocated.
Before you start
- Permutation prefixes and constraint pruning
- Row/column coordinates and diagonal invariants
Recognize the structure
Fixing exactly one queen per row removes the need to consider row conflicts. A valid solution is a column permutation with additional diagonal constraints. Reject partial attacks immediately rather than generating every column permutation first. Column c, r−c, and r+c identify the three resources owned by a queen.
Your Java attempt
Java 21 · Draft only. Your code is not compiled, executed, or graded here. Run it locally against the examples and edge cases.
Saving stores text in this browser, visible to other people using this browser profile. It does not sync to your account. Loading is always explicit.
No unsaved text changes · 192/20,000 characters
Self-review
Use the checklist to test your explanation. Checks apply to this visit.
Try before revealing
Hint 1
Fix one queen per row so only column and diagonal conflicts remain.
Hint 2
Which coordinate expressions stay constant along each diagonal direction?
Hint 3
Claim a free column and both diagonals, recurse to the next row, then restore all three flags and the row position.
Derive the solution
Reveal the baseline, optimized reasoning, and Java code
Generate every column permutation and test diagonals at the leaf
Place one queen in every row using each column exactly once, but defer diagonal validation until a complete permutation. Compare every pair of rows for equal absolute row/column differences and emit only nonattacking boards. This compiling baseline is complete but explores prefixes that already contain irreversible diagonal attacks.
Improve the baseline
Choose a compact board representation
positions[row] stores its queen column, with −1 for an unassigned row. Track occupied columns, down diagonals indexed by row−col+n−1, and up diagonals by row+col. Each diagonal array has 2n−1 positions for n>0; use zero length when n=0.
Admit only a safe next-row choice
For each column in ascending order, compute both diagonal slots. If any of the three resources is occupied, skip the candidate without changing state. Otherwise record positions[row], claim all three flags, and recurse to row+1.
Snapshot complete boards and release exact ownership
At row==n, construct independent row Strings from positions and append a new board list. On every return, set positions[row] back to −1 and clear the three flags just claimed. They cannot belong to an earlier queen because the admission checks guaranteed those slots were free.
Why it is correct
Sound partial boards
Rows below the current frontier are unassigned; every earlier row has exactly one queen. Column and diagonal flags describe exactly those active queens. A free triple cannot attack an earlier queen, so placing it preserves the invariant. Undo restores the parent state exactly.
Complete construction
Take any valid board and read its queen columns from row zero onward. At each row its column and diagonal slots are free relative to the valid earlier prefix, so the loop reaches and admits that choice. Therefore no valid board is removed by partial conflict pruning.
Unique enumeration and order
Each board determines one column choice per row, hence one root-to-leaf sequence. No sequence is repeated, and copied boards survive later undo. Row increases on every descent and is bounded by n. Ascending column choices order the column vectors lexicographically; keeping all orientations preserves all solutions.
Complete Java reference and baseline
Save as Solution.java. Node definitions and imports are included where needed. The baseline is included for comparison; respect its input-size limits.
import java.util.*;
public final class Solution {
private static void validate(int n){if(n<0||n>10)throw new IllegalArgumentException("n must be 0..10");}
private static List<String> board(int[] positions){List<String> board=new ArrayList<>();for(int col:positions){char[] row=new char[positions.length];Arrays.fill(row,'.');row[col]='Q';board.add(new String(row));}return board;}
private static void search(int row,int[] positions,boolean[] columns,boolean[] down,boolean[] up,List<List<String>> result) {
int n=positions.length;if(row==n){result.add(board(positions));return;}
for(int col=0;col<n;col++) {
int d=row-col+n-1,u=row+col;
if(columns[col]||down[d]||up[u])continue;
positions[row]=col;columns[col]=down[d]=up[u]=true;
search(row+1,positions,columns,down,up,result);
positions[row]=-1;columns[col]=down[d]=up[u]=false;
}
}
public static List<List<String>> solveNQueens(int n) {
validate(n);int[] positions=new int[n];Arrays.fill(positions,-1);List<List<String>> result=new ArrayList<>();search(0,positions,new boolean[n],new boolean[Math.max(0,2*n-1)],new boolean[Math.max(0,2*n-1)],result);return result;
}
private static void permutations(int row,int[] positions,boolean[] used,List<List<String>> result) {
if(row==positions.length){for(int a=0;a<row;a++)for(int b=0;b<a;b++)if(Math.abs(a-b)==Math.abs(positions[a]-positions[b]))return;result.add(board(positions));return;}
for(int col=0;col<positions.length;col++)if(!used[col]){used[col]=true;positions[row]=col;permutations(row+1,positions,used,result);used[col]=false;}
}
public static List<List<String>> baseline(int n) {
validate(n);List<List<String>> result=new ArrayList<>();permutations(0,new int[n],new boolean[n],result);return result;
}
}
Read the meaningful blocks
Diagonal identity uses a constant coordinate expression
Moving on one diagonal preserves row−col; moving on the other preserves row+col. Shift row−col by n−1 so its minimum becomes zero. Both indices lie in 0..2n−2 for a nonempty board.
Clearing a boolean is safe only with exclusive ownership
Two active queens must never share a column or diagonal. The admission guard establishes that exclusivity before setting flags; otherwise undoing one queen could erase another queen’s ownership. This explains why the invariant matters beyond detecting attacks.
Materialize only at complete leaves
Do not reuse positions or a mutable shared row-list as a stored board. Construct each String from a fresh char row and each board from a fresh list. Strings then stay stable while positions and flags are restored. A full n×n board costs Θ(n²) characters to output.
Complexity
Let K be the number of solutions. Since active columns never repeat, partial prefixes are bounded by the partial-permutation tree, O(n!) nodes for n≥1. Scanning n columns at internal frames gives a safe O(n·n!+K n²) time bound, including board materialization. Auxiliary positions, flags, recursion and temporary row construction use O(n+1); returned boards require Θ(1+K(n²+1)) character/list storage, with constant work/output for n=0.
The baseline explores complete column permutations and can test O(n²) row pairs at each leaf, giving O(n²·n!+K n²+1) time as a safe bound, O(n+1) auxiliary workspace, and the same output storage. Main diagonal flags reduce conflict-check work and prune earlier; neither method can avoid writing all requested boards. Trace frame histories and occupancy pictures are teaching views, not extra Java state.
Exact-state walkthroughs
Reveal normal and boundary traces
Safe placements prune attacks and produce both four-queen boards
Input: 4 · Nonattacking boards in column-vector order: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
Step 1 of 115: Initialize empty column and diagonal occupancy.
Row order is fixed. A queen at (r,c) owns column c, down diagonal r−c+n−1, and up diagonal r+c. Positions −1 mean no current queen in that row.
Phase: initial.
Place one queen per row. n=4. −1 means the row has no current queen.
Current column vector — row identities stay fixed
- row 0: unassigned
- row 1: unassigned
- row 2: unassigned
- row 3: unassigned
Column ownership
- column 0: free
- column 1: free
- column 2: free
- column 3: free
Down diagonals — slot = row − column + n − 1
- 0 (r−c=-3): free
- 1 (r−c=-2): free
- 2 (r−c=-1): free
- 3 (r−c=0): free
- 4 (r−c=1): free
- 5 (r−c=2): free
- 6 (r−c=3): free
Up diagonals — slot = row + column
- 0: free
- 1: free
- 2: free
- 3: free
- 4: free
- 5: free
- 6: free
Boards emitted so far: 0
No complete board has been emitted.
Boards are ordered by their column vectors. Reflections and rotations remain separate answers.
Logical recursive frames — root → active leaf, including suspended loop work
Empty.
These frame cards explain Java call-stack state; the implementation does not store a second history. Choose, child entry/return, and undo are distinct steps. Full state tables and static traces appear below; teaching snapshots are excluded from Java workspace costs.
| Variable | Value |
|---|---|
| input | 4 |
| positions | [-1,-1,-1,-1] |
| columns | [false,false,false,false] |
| down | [false,false,false,false,false,false,false] |
| up | [false,false,false,false,false,false,false] |
| frames | [] |
| boards | [] |
| phase | "initial" |
| row | null |
| column | null |
See the affected Java block
1 import java.util.*; 2 public final class Solution { 3 private static void validate(int n){if(n<0||n>10)throw new IllegalArgumentException("n must be 0..10");} 4 private static List<String> board(int[] positions){List<String> board=new ArrayList<>();for(int col:positions){char[] row=new char[positions.length];Arrays.fill(row,'.');row[col]='Q';board.add(new String(row));}return board;} 5 private static void search(int row,int[] positions,boolean[] columns,boolean[] down,boolean[] up,List<List<String>> result) { 6 int n=positions.length;if(row==n){result.add(board(positions));return;} 7 for(int col=0;col<n;col++) { 8 int d=row-col+n-1,u=row+col; 9 if(columns[col]||down[d]||up[u])continue; 10 positions[row]=col;columns[col]=down[d]=up[u]=true; 11 search(row+1,positions,columns,down,up,result); 12 positions[row]=-1;columns[col]=down[d]=up[u]=false; 13 } 14 } 15 public static List<List<String>> solveNQueens(int n) { 16 validate(n);int[] positions=new int[n];Arrays.fill(positions,-1);List<List<String>> result=new ArrayList<>();search(0,positions,new boolean[n],new boolean[Math.max(0,2*n-1)],new boolean[Math.max(0,2*n-1)],result);return result; 17 } 18 private static void permutations(int row,int[] positions,boolean[] used,List<List<String>> result) { 19 if(row==positions.length){for(int a=0;a<row;a++)for(int b=0;b<a;b++)if(Math.abs(a-b)==Math.abs(positions[a]-positions[b]))return;result.add(board(positions));return;} 20 for(int col=0;col<positions.length;col++)if(!used[col]){used[col]=true;positions[row]=col;permutations(row+1,positions,used,result);used[col]=false;} 21 } 22 public static List<List<String>> baseline(int n) { 23 validate(n);List<List<String>> result=new ArrayList<>();permutations(0,new int[n],new boolean[n],result);return result; 24 } 25 } 26
Highlight locates the relevant statement or block; one trace step may summarize several assignments.
Read the full static trace
- Initialize empty column and diagonal occupancy.
Row order is fixed. A queen at (r,c) owns column c, down diagonal r−c+n−1, and up diagonal r+c. Positions −1 mean no current queen in that row.
- input
4- positions
[-1,-1,-1,-1]- columns
[false,false,false,false]- down
[false,false,false,false,false,false,false]- up
[false,false,false,false,false,false,false]- frames
[]- boards
[]- phase
"initial"- row
null- column
null
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[-1,-1,-1,-1]- columns
[false,false,false,false]- down
[false,false,false,false,false,false,false]- up
[false,false,false,false,false,false,false]- frames
[{"row":0,"nextColumn":0,"choice":null}]- boards
[]- phase
"enter"- row
0- column
null
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[0,-1,-1,-1]- columns
[true,false,false,false]- down
[false,false,false,true,false,false,false]- up
[true,false,false,false,false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0}]- boards
[]- phase
"place"- row
0- column
0- d
3- u
0
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[0,-1,-1,-1]- columns
[true,false,false,false]- down
[false,false,false,true,false,false,false]- up
[true,false,false,false,false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":0,"choice":null}]- boards
[]- phase
"enter"- row
1- column
null
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[0,-1,-1,-1]- columns
[true,false,false,false]- down
[false,false,false,true,false,false,false]- up
[true,false,false,false,false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":1,"choice":null}]- boards
[]- phase
"reject"- row
1- column
0- d
4- u
1
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[0,-1,-1,-1]- columns
[true,false,false,false]- down
[false,false,false,true,false,false,false]- up
[true,false,false,false,false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":2,"choice":null}]- boards
[]- phase
"reject"- row
1- column
1- d
3- u
2
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[0,2,-1,-1]- columns
[true,false,true,false]- down
[false,false,true,true,false,false,false]- up
[true,false,false,true,false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":3,"choice":2}]- boards
[]- phase
"place"- row
1- column
2- d
2- u
3
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[0,2,-1,-1]- columns
[true,false,true,false]- down
[false,false,true,true,false,false,false]- up
[true,false,false,true,false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":3,"choice":2},{"row":2,"nextColumn":0,"choice":null}]- boards
[]- phase
"enter"- row
2- column
null
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[0,2,-1,-1]- columns
[true,false,true,false]- down
[false,false,true,true,false,false,false]- up
[true,false,false,true,false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":3,"choice":2},{"row":2,"nextColumn":1,"choice":null}]- boards
[]- phase
"reject"- row
2- column
0- d
5- u
2
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[0,2,-1,-1]- columns
[true,false,true,false]- down
[false,false,true,true,false,false,false]- up
[true,false,false,true,false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":3,"choice":2},{"row":2,"nextColumn":2,"choice":null}]- boards
[]- phase
"reject"- row
2- column
1- d
4- u
3
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[0,2,-1,-1]- columns
[true,false,true,false]- down
[false,false,true,true,false,false,false]- up
[true,false,false,true,false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":3,"choice":2},{"row":2,"nextColumn":3,"choice":null}]- boards
[]- phase
"reject"- row
2- column
2- d
3- u
4
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[0,2,-1,-1]- columns
[true,false,true,false]- down
[false,false,true,true,false,false,false]- up
[true,false,false,true,false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":3,"choice":2},{"row":2,"nextColumn":4,"choice":null}]- boards
[]- phase
"reject"- row
2- column
3- d
2- u
5
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[0,2,-1,-1]- columns
[true,false,true,false]- down
[false,false,true,true,false,false,false]- up
[true,false,false,true,false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":3,"choice":2}]- boards
[]- phase
"leave"- row
2- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[0,-1,-1,-1]- columns
[true,false,false,false]- down
[false,false,false,true,false,false,false]- up
[true,false,false,false,false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":3,"choice":null}]- boards
[]- phase
"undo"- row
1- column
2- d
2- u
3
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[0,3,-1,-1]- columns
[true,false,false,true]- down
[false,true,false,true,false,false,false]- up
[true,false,false,false,true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":4,"choice":3}]- boards
[]- phase
"place"- row
1- column
3- d
1- u
4
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[0,3,-1,-1]- columns
[true,false,false,true]- down
[false,true,false,true,false,false,false]- up
[true,false,false,false,true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":0,"choice":null}]- boards
[]- phase
"enter"- row
2- column
null
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[0,3,-1,-1]- columns
[true,false,false,true]- down
[false,true,false,true,false,false,false]- up
[true,false,false,false,true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":1,"choice":null}]- boards
[]- phase
"reject"- row
2- column
0- d
5- u
2
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[0,3,1,-1]- columns
[true,true,false,true]- down
[false,true,false,true,true,false,false]- up
[true,false,false,true,true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":2,"choice":1}]- boards
[]- phase
"place"- row
2- column
1- d
4- u
3
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[0,3,1,-1]- columns
[true,true,false,true]- down
[false,true,false,true,true,false,false]- up
[true,false,false,true,true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":2,"choice":1},{"row":3,"nextColumn":0,"choice":null}]- boards
[]- phase
"enter"- row
3- column
null
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[0,3,1,-1]- columns
[true,true,false,true]- down
[false,true,false,true,true,false,false]- up
[true,false,false,true,true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":2,"choice":1},{"row":3,"nextColumn":1,"choice":null}]- boards
[]- phase
"reject"- row
3- column
0- d
6- u
3
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[0,3,1,-1]- columns
[true,true,false,true]- down
[false,true,false,true,true,false,false]- up
[true,false,false,true,true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":2,"choice":1},{"row":3,"nextColumn":2,"choice":null}]- boards
[]- phase
"reject"- row
3- column
1- d
5- u
4
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[0,3,1,-1]- columns
[true,true,false,true]- down
[false,true,false,true,true,false,false]- up
[true,false,false,true,true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":2,"choice":1},{"row":3,"nextColumn":3,"choice":null}]- boards
[]- phase
"reject"- row
3- column
2- d
4- u
5
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[0,3,1,-1]- columns
[true,true,false,true]- down
[false,true,false,true,true,false,false]- up
[true,false,false,true,true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":2,"choice":1},{"row":3,"nextColumn":4,"choice":null}]- boards
[]- phase
"reject"- row
3- column
3- d
3- u
6
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[0,3,1,-1]- columns
[true,true,false,true]- down
[false,true,false,true,true,false,false]- up
[true,false,false,true,true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":2,"choice":1}]- boards
[]- phase
"leave"- row
3- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[0,3,-1,-1]- columns
[true,false,false,true]- down
[false,true,false,true,false,false,false]- up
[true,false,false,false,true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":2,"choice":null}]- boards
[]- phase
"undo"- row
2- column
1- d
4- u
3
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[0,3,-1,-1]- columns
[true,false,false,true]- down
[false,true,false,true,false,false,false]- up
[true,false,false,false,true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":3,"choice":null}]- boards
[]- phase
"reject"- row
2- column
2- d
3- u
4
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[0,3,-1,-1]- columns
[true,false,false,true]- down
[false,true,false,true,false,false,false]- up
[true,false,false,false,true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":4,"choice":null}]- boards
[]- phase
"reject"- row
2- column
3- d
2- u
5
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[0,3,-1,-1]- columns
[true,false,false,true]- down
[false,true,false,true,false,false,false]- up
[true,false,false,false,true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":4,"choice":3}]- boards
[]- phase
"leave"- row
2- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[0,-1,-1,-1]- columns
[true,false,false,false]- down
[false,false,false,true,false,false,false]- up
[true,false,false,false,false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":4,"choice":null}]- boards
[]- phase
"undo"- row
1- column
3- d
1- u
4
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[0,-1,-1,-1]- columns
[true,false,false,false]- down
[false,false,false,true,false,false,false]- up
[true,false,false,false,false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0}]- boards
[]- phase
"leave"- row
1- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[-1,-1,-1,-1]- columns
[false,false,false,false]- down
[false,false,false,false,false,false,false]- up
[false,false,false,false,false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":null}]- boards
[]- phase
"undo"- row
0- column
0- d
3- u
0
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[1,-1,-1,-1]- columns
[false,true,false,false]- down
[false,false,true,false,false,false,false]- up
[false,true,false,false,false,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1}]- boards
[]- phase
"place"- row
0- column
1- d
2- u
1
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[1,-1,-1,-1]- columns
[false,true,false,false]- down
[false,false,true,false,false,false,false]- up
[false,true,false,false,false,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":0,"choice":null}]- boards
[]- phase
"enter"- row
1- column
null
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[1,-1,-1,-1]- columns
[false,true,false,false]- down
[false,false,true,false,false,false,false]- up
[false,true,false,false,false,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":1,"choice":null}]- boards
[]- phase
"reject"- row
1- column
0- d
4- u
1
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[1,-1,-1,-1]- columns
[false,true,false,false]- down
[false,false,true,false,false,false,false]- up
[false,true,false,false,false,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":2,"choice":null}]- boards
[]- phase
"reject"- row
1- column
1- d
3- u
2
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[1,-1,-1,-1]- columns
[false,true,false,false]- down
[false,false,true,false,false,false,false]- up
[false,true,false,false,false,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":3,"choice":null}]- boards
[]- phase
"reject"- row
1- column
2- d
2- u
3
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[1,3,-1,-1]- columns
[false,true,false,true]- down
[false,true,true,false,false,false,false]- up
[false,true,false,false,true,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3}]- boards
[]- phase
"place"- row
1- column
3- d
1- u
4
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[1,3,-1,-1]- columns
[false,true,false,true]- down
[false,true,true,false,false,false,false]- up
[false,true,false,false,true,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":0,"choice":null}]- boards
[]- phase
"enter"- row
2- column
null
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[1,3,0,-1]- columns
[true,true,false,true]- down
[false,true,true,false,false,true,false]- up
[false,true,true,false,true,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":1,"choice":0}]- boards
[]- phase
"place"- row
2- column
0- d
5- u
2
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[1,3,0,-1]- columns
[true,true,false,true]- down
[false,true,true,false,false,true,false]- up
[false,true,true,false,true,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":1,"choice":0},{"row":3,"nextColumn":0,"choice":null}]- boards
[]- phase
"enter"- row
3- column
null
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[1,3,0,-1]- columns
[true,true,false,true]- down
[false,true,true,false,false,true,false]- up
[false,true,true,false,true,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":1,"choice":0},{"row":3,"nextColumn":1,"choice":null}]- boards
[]- phase
"reject"- row
3- column
0- d
6- u
3
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[1,3,0,-1]- columns
[true,true,false,true]- down
[false,true,true,false,false,true,false]- up
[false,true,true,false,true,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":1,"choice":0},{"row":3,"nextColumn":2,"choice":null}]- boards
[]- phase
"reject"- row
3- column
1- d
5- u
4
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[1,3,0,2]- columns
[true,true,true,true]- down
[false,true,true,false,true,true,false]- up
[false,true,true,false,true,true,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":1,"choice":0},{"row":3,"nextColumn":3,"choice":2}]- boards
[]- phase
"place"- row
3- column
2- d
4- u
5
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[1,3,0,2]- columns
[true,true,true,true]- down
[false,true,true,false,true,true,false]- up
[false,true,true,false,true,true,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":1,"choice":0},{"row":3,"nextColumn":3,"choice":2},{"row":4,"nextColumn":0,"choice":null}]- boards
[]- phase
"enter"- row
4- column
null
- Materialize one complete independent board.
Each board owns a mutable list of immutable row Strings. Empty n=0 contributes one empty arrangement. Rotations and reflections are retained as separate boards.
- input
4- positions
[1,3,0,2]- columns
[true,true,true,true]- down
[false,true,true,false,true,true,false]- up
[false,true,true,false,true,true,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":1,"choice":0},{"row":3,"nextColumn":3,"choice":2},{"row":4,"nextColumn":0,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"emit"- row
4- column
null
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[1,3,0,2]- columns
[true,true,true,true]- down
[false,true,true,false,true,true,false]- up
[false,true,true,false,true,true,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":1,"choice":0},{"row":3,"nextColumn":3,"choice":2}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"leave"- row
4- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[1,3,0,-1]- columns
[true,true,false,true]- down
[false,true,true,false,false,true,false]- up
[false,true,true,false,true,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":1,"choice":0},{"row":3,"nextColumn":3,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"undo"- row
3- column
2- d
4- u
5
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[1,3,0,-1]- columns
[true,true,false,true]- down
[false,true,true,false,false,true,false]- up
[false,true,true,false,true,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":1,"choice":0},{"row":3,"nextColumn":4,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"reject"- row
3- column
3- d
3- u
6
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[1,3,0,-1]- columns
[true,true,false,true]- down
[false,true,true,false,false,true,false]- up
[false,true,true,false,true,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":1,"choice":0}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"leave"- row
3- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[1,3,-1,-1]- columns
[false,true,false,true]- down
[false,true,true,false,false,false,false]- up
[false,true,false,false,true,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":1,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"undo"- row
2- column
0- d
5- u
2
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[1,3,-1,-1]- columns
[false,true,false,true]- down
[false,true,true,false,false,false,false]- up
[false,true,false,false,true,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":2,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"reject"- row
2- column
1- d
4- u
3
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[1,3,-1,-1]- columns
[false,true,false,true]- down
[false,true,true,false,false,false,false]- up
[false,true,false,false,true,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":3,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"reject"- row
2- column
2- d
3- u
4
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[1,3,-1,-1]- columns
[false,true,false,true]- down
[false,true,true,false,false,false,false]- up
[false,true,false,false,true,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3},{"row":2,"nextColumn":4,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"reject"- row
2- column
3- d
2- u
5
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[1,3,-1,-1]- columns
[false,true,false,true]- down
[false,true,true,false,false,false,false]- up
[false,true,false,false,true,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":3}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"leave"- row
2- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[1,-1,-1,-1]- columns
[false,true,false,false]- down
[false,false,true,false,false,false,false]- up
[false,true,false,false,false,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":4,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"undo"- row
1- column
3- d
1- u
4
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[1,-1,-1,-1]- columns
[false,true,false,false]- down
[false,false,true,false,false,false,false]- up
[false,true,false,false,false,false,false]- frames
[{"row":0,"nextColumn":2,"choice":1}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"leave"- row
1- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[-1,-1,-1,-1]- columns
[false,false,false,false]- down
[false,false,false,false,false,false,false]- up
[false,false,false,false,false,false,false]- frames
[{"row":0,"nextColumn":2,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"undo"- row
0- column
1- d
2- u
1
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[2,-1,-1,-1]- columns
[false,false,true,false]- down
[false,true,false,false,false,false,false]- up
[false,false,true,false,false,false,false]- frames
[{"row":0,"nextColumn":3,"choice":2}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"place"- row
0- column
2- d
1- u
2
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[2,-1,-1,-1]- columns
[false,false,true,false]- down
[false,true,false,false,false,false,false]- up
[false,false,true,false,false,false,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":0,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"enter"- row
1- column
null
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[2,0,-1,-1]- columns
[true,false,true,false]- down
[false,true,false,false,true,false,false]- up
[false,true,true,false,false,false,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"place"- row
1- column
0- d
4- u
1
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[2,0,-1,-1]- columns
[true,false,true,false]- down
[false,true,false,false,true,false,false]- up
[false,true,true,false,false,false,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":0,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"enter"- row
2- column
null
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[2,0,-1,-1]- columns
[true,false,true,false]- down
[false,true,false,false,true,false,false]- up
[false,true,true,false,false,false,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":1,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"reject"- row
2- column
0- d
5- u
2
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[2,0,-1,-1]- columns
[true,false,true,false]- down
[false,true,false,false,true,false,false]- up
[false,true,true,false,false,false,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":2,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"reject"- row
2- column
1- d
4- u
3
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[2,0,-1,-1]- columns
[true,false,true,false]- down
[false,true,false,false,true,false,false]- up
[false,true,true,false,false,false,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":3,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"reject"- row
2- column
2- d
3- u
4
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[2,0,3,-1]- columns
[true,false,true,true]- down
[false,true,true,false,true,false,false]- up
[false,true,true,false,false,true,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":4,"choice":3}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"place"- row
2- column
3- d
2- u
5
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[2,0,3,-1]- columns
[true,false,true,true]- down
[false,true,true,false,true,false,false]- up
[false,true,true,false,false,true,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":4,"choice":3},{"row":3,"nextColumn":0,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"enter"- row
3- column
null
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[2,0,3,-1]- columns
[true,false,true,true]- down
[false,true,true,false,true,false,false]- up
[false,true,true,false,false,true,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":4,"choice":3},{"row":3,"nextColumn":1,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"reject"- row
3- column
0- d
6- u
3
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[2,0,3,1]- columns
[true,true,true,true]- down
[false,true,true,false,true,true,false]- up
[false,true,true,false,true,true,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":4,"choice":3},{"row":3,"nextColumn":2,"choice":1}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"place"- row
3- column
1- d
5- u
4
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[2,0,3,1]- columns
[true,true,true,true]- down
[false,true,true,false,true,true,false]- up
[false,true,true,false,true,true,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":4,"choice":3},{"row":3,"nextColumn":2,"choice":1},{"row":4,"nextColumn":0,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."]]- phase
"enter"- row
4- column
null
- Materialize one complete independent board.
Each board owns a mutable list of immutable row Strings. Empty n=0 contributes one empty arrangement. Rotations and reflections are retained as separate boards.
- input
4- positions
[2,0,3,1]- columns
[true,true,true,true]- down
[false,true,true,false,true,true,false]- up
[false,true,true,false,true,true,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":4,"choice":3},{"row":3,"nextColumn":2,"choice":1},{"row":4,"nextColumn":0,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"emit"- row
4- column
null
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[2,0,3,1]- columns
[true,true,true,true]- down
[false,true,true,false,true,true,false]- up
[false,true,true,false,true,true,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":4,"choice":3},{"row":3,"nextColumn":2,"choice":1}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"leave"- row
4- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[2,0,3,-1]- columns
[true,false,true,true]- down
[false,true,true,false,true,false,false]- up
[false,true,true,false,false,true,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":4,"choice":3},{"row":3,"nextColumn":2,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"undo"- row
3- column
1- d
5- u
4
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[2,0,3,-1]- columns
[true,false,true,true]- down
[false,true,true,false,true,false,false]- up
[false,true,true,false,false,true,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":4,"choice":3},{"row":3,"nextColumn":3,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
3- column
2- d
4- u
5
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[2,0,3,-1]- columns
[true,false,true,true]- down
[false,true,true,false,true,false,false]- up
[false,true,true,false,false,true,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":4,"choice":3},{"row":3,"nextColumn":4,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
3- column
3- d
3- u
6
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[2,0,3,-1]- columns
[true,false,true,true]- down
[false,true,true,false,true,false,false]- up
[false,true,true,false,false,true,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":4,"choice":3}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"leave"- row
3- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[2,0,-1,-1]- columns
[true,false,true,false]- down
[false,true,false,false,true,false,false]- up
[false,true,true,false,false,false,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":4,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"undo"- row
2- column
3- d
2- u
5
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[2,0,-1,-1]- columns
[true,false,true,false]- down
[false,true,false,false,true,false,false]- up
[false,true,true,false,false,false,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":0}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"leave"- row
2- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[2,-1,-1,-1]- columns
[false,false,true,false]- down
[false,true,false,false,false,false,false]- up
[false,false,true,false,false,false,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":1,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"undo"- row
1- column
0- d
4- u
1
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[2,-1,-1,-1]- columns
[false,false,true,false]- down
[false,true,false,false,false,false,false]- up
[false,false,true,false,false,false,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":2,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
1- column
1- d
3- u
2
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[2,-1,-1,-1]- columns
[false,false,true,false]- down
[false,true,false,false,false,false,false]- up
[false,false,true,false,false,false,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":3,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
1- column
2- d
2- u
3
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[2,-1,-1,-1]- columns
[false,false,true,false]- down
[false,true,false,false,false,false,false]- up
[false,false,true,false,false,false,false]- frames
[{"row":0,"nextColumn":3,"choice":2},{"row":1,"nextColumn":4,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
1- column
3- d
1- u
4
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[2,-1,-1,-1]- columns
[false,false,true,false]- down
[false,true,false,false,false,false,false]- up
[false,false,true,false,false,false,false]- frames
[{"row":0,"nextColumn":3,"choice":2}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"leave"- row
1- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[-1,-1,-1,-1]- columns
[false,false,false,false]- down
[false,false,false,false,false,false,false]- up
[false,false,false,false,false,false,false]- frames
[{"row":0,"nextColumn":3,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"undo"- row
0- column
2- d
1- u
2
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[3,-1,-1,-1]- columns
[false,false,false,true]- down
[true,false,false,false,false,false,false]- up
[false,false,false,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"place"- row
0- column
3- d
0- u
3
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[3,-1,-1,-1]- columns
[false,false,false,true]- down
[true,false,false,false,false,false,false]- up
[false,false,false,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":0,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"enter"- row
1- column
null
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[3,0,-1,-1]- columns
[true,false,false,true]- down
[true,false,false,false,true,false,false]- up
[false,true,false,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":1,"choice":0}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"place"- row
1- column
0- d
4- u
1
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[3,0,-1,-1]- columns
[true,false,false,true]- down
[true,false,false,false,true,false,false]- up
[false,true,false,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":0,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"enter"- row
2- column
null
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[3,0,-1,-1]- columns
[true,false,false,true]- down
[true,false,false,false,true,false,false]- up
[false,true,false,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":1,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
2- column
0- d
5- u
2
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[3,0,-1,-1]- columns
[true,false,false,true]- down
[true,false,false,false,true,false,false]- up
[false,true,false,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":2,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
2- column
1- d
4- u
3
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[3,0,2,-1]- columns
[true,false,true,true]- down
[true,false,false,true,true,false,false]- up
[false,true,false,true,true,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":3,"choice":2}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"place"- row
2- column
2- d
3- u
4
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[3,0,2,-1]- columns
[true,false,true,true]- down
[true,false,false,true,true,false,false]- up
[false,true,false,true,true,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":3,"choice":2},{"row":3,"nextColumn":0,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"enter"- row
3- column
null
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[3,0,2,-1]- columns
[true,false,true,true]- down
[true,false,false,true,true,false,false]- up
[false,true,false,true,true,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":3,"choice":2},{"row":3,"nextColumn":1,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
3- column
0- d
6- u
3
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[3,0,2,-1]- columns
[true,false,true,true]- down
[true,false,false,true,true,false,false]- up
[false,true,false,true,true,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":3,"choice":2},{"row":3,"nextColumn":2,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
3- column
1- d
5- u
4
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[3,0,2,-1]- columns
[true,false,true,true]- down
[true,false,false,true,true,false,false]- up
[false,true,false,true,true,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":3,"choice":2},{"row":3,"nextColumn":3,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
3- column
2- d
4- u
5
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[3,0,2,-1]- columns
[true,false,true,true]- down
[true,false,false,true,true,false,false]- up
[false,true,false,true,true,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":3,"choice":2},{"row":3,"nextColumn":4,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
3- column
3- d
3- u
6
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[3,0,2,-1]- columns
[true,false,true,true]- down
[true,false,false,true,true,false,false]- up
[false,true,false,true,true,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":3,"choice":2}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"leave"- row
3- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[3,0,-1,-1]- columns
[true,false,false,true]- down
[true,false,false,false,true,false,false]- up
[false,true,false,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":3,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"undo"- row
2- column
2- d
3- u
4
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[3,0,-1,-1]- columns
[true,false,false,true]- down
[true,false,false,false,true,false,false]- up
[false,true,false,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":1,"choice":0},{"row":2,"nextColumn":4,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
2- column
3- d
2- u
5
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[3,0,-1,-1]- columns
[true,false,false,true]- down
[true,false,false,false,true,false,false]- up
[false,true,false,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":1,"choice":0}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"leave"- row
2- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[3,-1,-1,-1]- columns
[false,false,false,true]- down
[true,false,false,false,false,false,false]- up
[false,false,false,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":1,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"undo"- row
1- column
0- d
4- u
1
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
4- positions
[3,1,-1,-1]- columns
[false,true,false,true]- down
[true,false,false,true,false,false,false]- up
[false,false,true,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":2,"choice":1}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"place"- row
1- column
1- d
3- u
2
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
4- positions
[3,1,-1,-1]- columns
[false,true,false,true]- down
[true,false,false,true,false,false,false]- up
[false,false,true,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":2,"choice":1},{"row":2,"nextColumn":0,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"enter"- row
2- column
null
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[3,1,-1,-1]- columns
[false,true,false,true]- down
[true,false,false,true,false,false,false]- up
[false,false,true,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":2,"choice":1},{"row":2,"nextColumn":1,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
2- column
0- d
5- u
2
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[3,1,-1,-1]- columns
[false,true,false,true]- down
[true,false,false,true,false,false,false]- up
[false,false,true,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":2,"choice":1},{"row":2,"nextColumn":2,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
2- column
1- d
4- u
3
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[3,1,-1,-1]- columns
[false,true,false,true]- down
[true,false,false,true,false,false,false]- up
[false,false,true,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":2,"choice":1},{"row":2,"nextColumn":3,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
2- column
2- d
3- u
4
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[3,1,-1,-1]- columns
[false,true,false,true]- down
[true,false,false,true,false,false,false]- up
[false,false,true,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":2,"choice":1},{"row":2,"nextColumn":4,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
2- column
3- d
2- u
5
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[3,1,-1,-1]- columns
[false,true,false,true]- down
[true,false,false,true,false,false,false]- up
[false,false,true,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":2,"choice":1}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"leave"- row
2- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[3,-1,-1,-1]- columns
[false,false,false,true]- down
[true,false,false,false,false,false,false]- up
[false,false,false,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":2,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"undo"- row
1- column
1- d
3- u
2
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[3,-1,-1,-1]- columns
[false,false,false,true]- down
[true,false,false,false,false,false,false]- up
[false,false,false,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":3,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
1- column
2- d
2- u
3
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
4- positions
[3,-1,-1,-1]- columns
[false,false,false,true]- down
[true,false,false,false,false,false,false]- up
[false,false,false,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3},{"row":1,"nextColumn":4,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"reject"- row
1- column
3- d
1- u
4
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[3,-1,-1,-1]- columns
[false,false,false,true]- down
[true,false,false,false,false,false,false]- up
[false,false,false,true,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":3}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"leave"- row
1- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
4- positions
[-1,-1,-1,-1]- columns
[false,false,false,false]- down
[false,false,false,false,false,false,false]- up
[false,false,false,false,false,false,false]- frames
[{"row":0,"nextColumn":4,"choice":null}]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"undo"- row
0- column
3- d
0- u
3
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
4- positions
[-1,-1,-1,-1]- columns
[false,false,false,false]- down
[false,false,false,false,false,false,false]- up
[false,false,false,false,false,false,false]- frames
[]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"leave"- row
0- column
null
- Return every board in ascending column-choice order.
All marks are released. Board order follows column vectors lexicographically, not necessarily lexicographic order of the printed dots and Q characters.
- input
4- positions
[-1,-1,-1,-1]- columns
[false,false,false,false]- down
[false,false,false,false,false,false,false]- up
[false,false,false,false,false,false,false]- frames
[]- boards
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]- phase
"complete"- row
null- column
null
- Return the documented result.
Exact traces preserve the original fixture. Output/history snapshots used for teaching are separate from the implementation’s live workspace.
- result
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
Two queens cannot avoid attacks
Input: 2 · Nonattacking boards in column-vector order: []
Step 1 of 17: Initialize empty column and diagonal occupancy.
Row order is fixed. A queen at (r,c) owns column c, down diagonal r−c+n−1, and up diagonal r+c. Positions −1 mean no current queen in that row.
Phase: initial.
Place one queen per row. n=2. −1 means the row has no current queen.
Current column vector — row identities stay fixed
- row 0: unassigned
- row 1: unassigned
Column ownership
- column 0: free
- column 1: free
Down diagonals — slot = row − column + n − 1
- 0 (r−c=-1): free
- 1 (r−c=0): free
- 2 (r−c=1): free
Up diagonals — slot = row + column
- 0: free
- 1: free
- 2: free
Boards emitted so far: 0
No complete board has been emitted.
Boards are ordered by their column vectors. Reflections and rotations remain separate answers.
Logical recursive frames — root → active leaf, including suspended loop work
Empty.
These frame cards explain Java call-stack state; the implementation does not store a second history. Choose, child entry/return, and undo are distinct steps. Full state tables and static traces appear below; teaching snapshots are excluded from Java workspace costs.
| Variable | Value |
|---|---|
| input | 2 |
| positions | [-1,-1] |
| columns | [false,false] |
| down | [false,false,false] |
| up | [false,false,false] |
| frames | [] |
| boards | [] |
| phase | "initial" |
| row | null |
| column | null |
See the affected Java block
1 import java.util.*; 2 public final class Solution { 3 private static void validate(int n){if(n<0||n>10)throw new IllegalArgumentException("n must be 0..10");} 4 private static List<String> board(int[] positions){List<String> board=new ArrayList<>();for(int col:positions){char[] row=new char[positions.length];Arrays.fill(row,'.');row[col]='Q';board.add(new String(row));}return board;} 5 private static void search(int row,int[] positions,boolean[] columns,boolean[] down,boolean[] up,List<List<String>> result) { 6 int n=positions.length;if(row==n){result.add(board(positions));return;} 7 for(int col=0;col<n;col++) { 8 int d=row-col+n-1,u=row+col; 9 if(columns[col]||down[d]||up[u])continue; 10 positions[row]=col;columns[col]=down[d]=up[u]=true; 11 search(row+1,positions,columns,down,up,result); 12 positions[row]=-1;columns[col]=down[d]=up[u]=false; 13 } 14 } 15 public static List<List<String>> solveNQueens(int n) { 16 validate(n);int[] positions=new int[n];Arrays.fill(positions,-1);List<List<String>> result=new ArrayList<>();search(0,positions,new boolean[n],new boolean[Math.max(0,2*n-1)],new boolean[Math.max(0,2*n-1)],result);return result; 17 } 18 private static void permutations(int row,int[] positions,boolean[] used,List<List<String>> result) { 19 if(row==positions.length){for(int a=0;a<row;a++)for(int b=0;b<a;b++)if(Math.abs(a-b)==Math.abs(positions[a]-positions[b]))return;result.add(board(positions));return;} 20 for(int col=0;col<positions.length;col++)if(!used[col]){used[col]=true;positions[row]=col;permutations(row+1,positions,used,result);used[col]=false;} 21 } 22 public static List<List<String>> baseline(int n) { 23 validate(n);List<List<String>> result=new ArrayList<>();permutations(0,new int[n],new boolean[n],result);return result; 24 } 25 } 26
Highlight locates the relevant statement or block; one trace step may summarize several assignments.
Read the full static trace
- Initialize empty column and diagonal occupancy.
Row order is fixed. A queen at (r,c) owns column c, down diagonal r−c+n−1, and up diagonal r+c. Positions −1 mean no current queen in that row.
- input
2- positions
[-1,-1]- columns
[false,false]- down
[false,false,false]- up
[false,false,false]- frames
[]- boards
[]- phase
"initial"- row
null- column
null
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
2- positions
[-1,-1]- columns
[false,false]- down
[false,false,false]- up
[false,false,false]- frames
[{"row":0,"nextColumn":0,"choice":null}]- boards
[]- phase
"enter"- row
0- column
null
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
2- positions
[0,-1]- columns
[true,false]- down
[false,true,false]- up
[true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0}]- boards
[]- phase
"place"- row
0- column
0- d
1- u
0
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
2- positions
[0,-1]- columns
[true,false]- down
[false,true,false]- up
[true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":0,"choice":null}]- boards
[]- phase
"enter"- row
1- column
null
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
2- positions
[0,-1]- columns
[true,false]- down
[false,true,false]- up
[true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":1,"choice":null}]- boards
[]- phase
"reject"- row
1- column
0- d
2- u
1
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
2- positions
[0,-1]- columns
[true,false]- down
[false,true,false]- up
[true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":2,"choice":null}]- boards
[]- phase
"reject"- row
1- column
1- d
1- u
2
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
2- positions
[0,-1]- columns
[true,false]- down
[false,true,false]- up
[true,false,false]- frames
[{"row":0,"nextColumn":1,"choice":0}]- boards
[]- phase
"leave"- row
1- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
2- positions
[-1,-1]- columns
[false,false]- down
[false,false,false]- up
[false,false,false]- frames
[{"row":0,"nextColumn":1,"choice":null}]- boards
[]- phase
"undo"- row
0- column
0- d
1- u
0
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
2- positions
[1,-1]- columns
[false,true]- down
[true,false,false]- up
[false,true,false]- frames
[{"row":0,"nextColumn":2,"choice":1}]- boards
[]- phase
"place"- row
0- column
1- d
0- u
1
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
2- positions
[1,-1]- columns
[false,true]- down
[true,false,false]- up
[false,true,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":0,"choice":null}]- boards
[]- phase
"enter"- row
1- column
null
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
2- positions
[1,-1]- columns
[false,true]- down
[true,false,false]- up
[false,true,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":1,"choice":null}]- boards
[]- phase
"reject"- row
1- column
0- d
2- u
1
- Reject an attacking column or diagonal before descending.
A rejected candidate changes no position or occupancy mark. Constant-time conflict checks replace a scan of earlier queens.
- input
2- positions
[1,-1]- columns
[false,true]- down
[true,false,false]- up
[false,true,false]- frames
[{"row":0,"nextColumn":2,"choice":1},{"row":1,"nextColumn":2,"choice":null}]- boards
[]- phase
"reject"- row
1- column
1- d
1- u
2
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
2- positions
[1,-1]- columns
[false,true]- down
[true,false,false]- up
[false,true,false]- frames
[{"row":0,"nextColumn":2,"choice":1}]- boards
[]- phase
"leave"- row
1- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
2- positions
[-1,-1]- columns
[false,false]- down
[false,false,false]- up
[false,false,false]- frames
[{"row":0,"nextColumn":2,"choice":null}]- boards
[]- phase
"undo"- row
0- column
1- d
0- u
1
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
2- positions
[-1,-1]- columns
[false,false]- down
[false,false,false]- up
[false,false,false]- frames
[]- boards
[]- phase
"leave"- row
0- column
null
- Return every board in ascending column-choice order.
All marks are released. Board order follows column vectors lexicographically, not necessarily lexicographic order of the printed dots and Q characters.
- input
2- positions
[-1,-1]- columns
[false,false]- down
[false,false,false]- up
[false,false,false]- frames
[]- boards
[]- phase
"complete"- row
null- column
null
- Return the documented result.
Exact traces preserve the original fixture. Output/history snapshots used for teaching are separate from the implementation’s live workspace.
- result
[]
An empty board is one arrangement
Input: 0 · Nonattacking boards in column-vector order: [[]]
Step 1 of 6: Initialize empty column and diagonal occupancy.
Row order is fixed. A queen at (r,c) owns column c, down diagonal r−c+n−1, and up diagonal r+c. Positions −1 mean no current queen in that row.
Phase: initial.
Place one queen per row. n=0. −1 means the row has no current queen.
No rows or diagonal slots are needed for n=0.
Current column vector — row identities stay fixed
Empty.
Column ownership
Empty.
Down diagonals — slot = row − column + n − 1
Empty.
Up diagonals — slot = row + column
Empty.
Boards emitted so far: 0
No complete board has been emitted.
Boards are ordered by their column vectors. Reflections and rotations remain separate answers.
Logical recursive frames — root → active leaf, including suspended loop work
Empty.
These frame cards explain Java call-stack state; the implementation does not store a second history. Choose, child entry/return, and undo are distinct steps. Full state tables and static traces appear below; teaching snapshots are excluded from Java workspace costs.
| Variable | Value |
|---|---|
| input | 0 |
| positions | [] |
| columns | [] |
| down | [] |
| up | [] |
| frames | [] |
| boards | [] |
| phase | "initial" |
| row | null |
| column | null |
See the affected Java block
1 import java.util.*; 2 public final class Solution { 3 private static void validate(int n){if(n<0||n>10)throw new IllegalArgumentException("n must be 0..10");} 4 private static List<String> board(int[] positions){List<String> board=new ArrayList<>();for(int col:positions){char[] row=new char[positions.length];Arrays.fill(row,'.');row[col]='Q';board.add(new String(row));}return board;} 5 private static void search(int row,int[] positions,boolean[] columns,boolean[] down,boolean[] up,List<List<String>> result) { 6 int n=positions.length;if(row==n){result.add(board(positions));return;} 7 for(int col=0;col<n;col++) { 8 int d=row-col+n-1,u=row+col; 9 if(columns[col]||down[d]||up[u])continue; 10 positions[row]=col;columns[col]=down[d]=up[u]=true; 11 search(row+1,positions,columns,down,up,result); 12 positions[row]=-1;columns[col]=down[d]=up[u]=false; 13 } 14 } 15 public static List<List<String>> solveNQueens(int n) { 16 validate(n);int[] positions=new int[n];Arrays.fill(positions,-1);List<List<String>> result=new ArrayList<>();search(0,positions,new boolean[n],new boolean[Math.max(0,2*n-1)],new boolean[Math.max(0,2*n-1)],result);return result; 17 } 18 private static void permutations(int row,int[] positions,boolean[] used,List<List<String>> result) { 19 if(row==positions.length){for(int a=0;a<row;a++)for(int b=0;b<a;b++)if(Math.abs(a-b)==Math.abs(positions[a]-positions[b]))return;result.add(board(positions));return;} 20 for(int col=0;col<positions.length;col++)if(!used[col]){used[col]=true;positions[row]=col;permutations(row+1,positions,used,result);used[col]=false;} 21 } 22 public static List<List<String>> baseline(int n) { 23 validate(n);List<List<String>> result=new ArrayList<>();permutations(0,new int[n],new boolean[n],result);return result; 24 } 25 } 26
Highlight locates the relevant statement or block; one trace step may summarize several assignments.
Read the full static trace
- Initialize empty column and diagonal occupancy.
Row order is fixed. A queen at (r,c) owns column c, down diagonal r−c+n−1, and up diagonal r+c. Positions −1 mean no current queen in that row.
- input
0- positions
[]- columns
[]- down
[]- up
[]- frames
[]- boards
[]- phase
"initial"- row
null- column
null
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
0- positions
[]- columns
[]- down
[]- up
[]- frames
[{"row":0,"nextColumn":0,"choice":null}]- boards
[]- phase
"enter"- row
0- column
null
- Materialize one complete independent board.
Each board owns a mutable list of immutable row Strings. Empty n=0 contributes one empty arrangement. Rotations and reflections are retained as separate boards.
- input
0- positions
[]- columns
[]- down
[]- up
[]- frames
[{"row":0,"nextColumn":0,"choice":null}]- boards
[[]]- phase
"emit"- row
0- column
null
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
0- positions
[]- columns
[]- down
[]- up
[]- frames
[]- boards
[[]]- phase
"leave"- row
0- column
null
- Return every board in ascending column-choice order.
All marks are released. Board order follows column vectors lexicographically, not necessarily lexicographic order of the printed dots and Q characters.
- input
0- positions
[]- columns
[]- down
[]- up
[]- frames
[]- boards
[[]]- phase
"complete"- row
null- column
null
- Return the documented result.
Exact traces preserve the original fixture. Output/history snapshots used for teaching are separate from the implementation’s live workspace.
- result
[[]]
One queen owns one column and two diagonal slots
Input: 1 · Nonattacking boards in column-vector order: [["Q"]]
Step 1 of 10: Initialize empty column and diagonal occupancy.
Row order is fixed. A queen at (r,c) owns column c, down diagonal r−c+n−1, and up diagonal r+c. Positions −1 mean no current queen in that row.
Phase: initial.
Place one queen per row. n=1. −1 means the row has no current queen.
Current column vector — row identities stay fixed
- row 0: unassigned
Column ownership
- column 0: free
Down diagonals — slot = row − column + n − 1
- 0 (r−c=0): free
Up diagonals — slot = row + column
- 0: free
Boards emitted so far: 0
No complete board has been emitted.
Boards are ordered by their column vectors. Reflections and rotations remain separate answers.
Logical recursive frames — root → active leaf, including suspended loop work
Empty.
These frame cards explain Java call-stack state; the implementation does not store a second history. Choose, child entry/return, and undo are distinct steps. Full state tables and static traces appear below; teaching snapshots are excluded from Java workspace costs.
| Variable | Value |
|---|---|
| input | 1 |
| positions | [-1] |
| columns | [false] |
| down | [false] |
| up | [false] |
| frames | [] |
| boards | [] |
| phase | "initial" |
| row | null |
| column | null |
See the affected Java block
1 import java.util.*; 2 public final class Solution { 3 private static void validate(int n){if(n<0||n>10)throw new IllegalArgumentException("n must be 0..10");} 4 private static List<String> board(int[] positions){List<String> board=new ArrayList<>();for(int col:positions){char[] row=new char[positions.length];Arrays.fill(row,'.');row[col]='Q';board.add(new String(row));}return board;} 5 private static void search(int row,int[] positions,boolean[] columns,boolean[] down,boolean[] up,List<List<String>> result) { 6 int n=positions.length;if(row==n){result.add(board(positions));return;} 7 for(int col=0;col<n;col++) { 8 int d=row-col+n-1,u=row+col; 9 if(columns[col]||down[d]||up[u])continue; 10 positions[row]=col;columns[col]=down[d]=up[u]=true; 11 search(row+1,positions,columns,down,up,result); 12 positions[row]=-1;columns[col]=down[d]=up[u]=false; 13 } 14 } 15 public static List<List<String>> solveNQueens(int n) { 16 validate(n);int[] positions=new int[n];Arrays.fill(positions,-1);List<List<String>> result=new ArrayList<>();search(0,positions,new boolean[n],new boolean[Math.max(0,2*n-1)],new boolean[Math.max(0,2*n-1)],result);return result; 17 } 18 private static void permutations(int row,int[] positions,boolean[] used,List<List<String>> result) { 19 if(row==positions.length){for(int a=0;a<row;a++)for(int b=0;b<a;b++)if(Math.abs(a-b)==Math.abs(positions[a]-positions[b]))return;result.add(board(positions));return;} 20 for(int col=0;col<positions.length;col++)if(!used[col]){used[col]=true;positions[row]=col;permutations(row+1,positions,used,result);used[col]=false;} 21 } 22 public static List<List<String>> baseline(int n) { 23 validate(n);List<List<String>> result=new ArrayList<>();permutations(0,new int[n],new boolean[n],result);return result; 24 } 25 } 26
Highlight locates the relevant statement or block; one trace step may summarize several assignments.
Read the full static trace
- Initialize empty column and diagonal occupancy.
Row order is fixed. A queen at (r,c) owns column c, down diagonal r−c+n−1, and up diagonal r+c. Positions −1 mean no current queen in that row.
- input
1- positions
[-1]- columns
[false]- down
[false]- up
[false]- frames
[]- boards
[]- phase
"initial"- row
null- column
null
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
1- positions
[-1]- columns
[false]- down
[false]- up
[false]- frames
[{"row":0,"nextColumn":0,"choice":null}]- boards
[]- phase
"enter"- row
0- column
null
- Place a nonattacking queen for this row.
The selected column is appended to a valid prefix. The three owned flags are distinct from those of all earlier queens.
- input
1- positions
[0]- columns
[true]- down
[true]- up
[true]- frames
[{"row":0,"nextColumn":1,"choice":0}]- boards
[]- phase
"place"- row
0- column
0- d
0- u
0
- Enter the next row while preserving all earlier choices.
Exactly the earlier rows are assigned at entry. Occupancy is derived from those active queens, not from boards emitted on earlier branches.
- input
1- positions
[0]- columns
[true]- down
[true]- up
[true]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":0,"choice":null}]- boards
[]- phase
"enter"- row
1- column
null
- Materialize one complete independent board.
Each board owns a mutable list of immutable row Strings. Empty n=0 contributes one empty arrangement. Rotations and reflections are retained as separate boards.
- input
1- positions
[0]- columns
[true]- down
[true]- up
[true]- frames
[{"row":0,"nextColumn":1,"choice":0},{"row":1,"nextColumn":0,"choice":null}]- boards
[["Q"]]- phase
"emit"- row
1- column
null
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
1- positions
[0]- columns
[true]- down
[true]- up
[true]- frames
[{"row":0,"nextColumn":1,"choice":0}]- boards
[["Q"]]- phase
"leave"- row
1- column
null
- Undo this queen before considering the next column.
Only this row’s ownership is released. Previously emitted board Strings do not change when positions is restored.
- input
1- positions
[-1]- columns
[false]- down
[false]- up
[false]- frames
[{"row":0,"nextColumn":1,"choice":null}]- boards
[["Q"]]- phase
"undo"- row
0- column
0- d
0- u
0
- Return from the completed row search.
The caller’s active choices remain; an undo in that caller follows a child return. The logical frame history is teaching state, not additional Java storage.
- input
1- positions
[-1]- columns
[false]- down
[false]- up
[false]- frames
[]- boards
[["Q"]]- phase
"leave"- row
0- column
null
- Return every board in ascending column-choice order.
All marks are released. Board order follows column vectors lexicographically, not necessarily lexicographic order of the printed dots and Q characters.
- input
1- positions
[-1]- columns
[false]- down
[false]- up
[false]- frames
[]- boards
[["Q"]]- phase
"complete"- row
null- column
null
- Return the documented result.
Exact traces preserve the original fixture. Output/history snapshots used for teaching are separate from the implementation’s live workspace.
- result
[["Q"]]
Test the contract
Input:
n=0 and n=1
Output:one board eachChecks empty construction and the first real queen.
Input:
n=2 and n=3
Output:no boardsAll column permutations have diagonal attacks.
Input:
n=4
Output:two boards with vectors [1,3,0,2] then [2,0,3,1]Tests complete enumeration and column-vector order.
Input:
All n through six
Output:matches exhaustive n^n column assignmentsThe independent oracle does not use main occupancy flags or prune partial attacks.
Input:
n through ten
Output:counts 1,1,0,0,2,10,4,40,92,352,724Every returned board is checked pairwise for attacks and repeated calls share no mutable containers.
Common mistakes and counterexamples
Use the same expression for both diagonals
Counterexample: Equal row−col detects only one diagonal direction.
Track row−col+n−1 and row+col separately.
Clear flags that an earlier queen also owns
Counterexample: Removing one queen can falsely free an attacked line.
Reject occupied resources before placement so each active flag has one owner.
Return a shared board list
Counterexample: Later emitted rows or undo can change earlier answers.
Create independent board containers and immutable row Strings.
Handle n=0 as no solution or allocate 2n−1 directly
Counterexample: The empty arrangement exists, but 2·0−1 is a negative array length.
Emit one empty board and allocate diagonal lengths with max(0,2n−1).
Follow-ups
Count arrangements without building boards.
Increment a numeric counter at complete leaves instead of constructing Strings. Use a numeric type with an explicit range guarantee; removing output materialization changes the storage bound but not the underlying search.
Use bit masks for occupancy.
Columns and shifted diagonal attack masks can accelerate candidate selection for a bounded n. Define word-width and shift behavior carefully, especially signed shifts and n equal to the mask width. Validate the bit version against these independent small-board oracles.
Exploit mirror symmetry.
Pair first-row choices with their reflected columns and handle a central column separately for odd n. Counting can exploit pairing more directly; enumeration must still return both orientations when this contract treats them as distinct.