N-Queens
Updated
Problem statement
Place n queens on an n by n chessboard so that no two share a row, column, or diagonal. Return every valid board. Each board is n strings, using Q for a queen and . for an empty cell. Order solutions by their vector of queen column indices (row zero first), ascending lexicographically. Return an empty list if no placement exists.
Function
solveNQueens(n: int) → List<List<String>>Examples
Example 1
n = 4return = [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]The two valid queen-column vectors are [1,3,0,2] and [2,0,3,1].
Example 2
n = 1return = [["Q"]]A single queen attacks no other queen.
Constraints
- For this exercise, assume 1 <= n <= 9. Board coordinates start at zero.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Alternating Parity PermutationsGoldman Sachs · OAGoldman Sachs interview questions
- PermutationsAtlassian · OAAtlassian interview questions
- Generate Parameter CombinationsGecko Robotics · OA · PHONE SCREEN
- Count Legal Outfit CombinationsDuolingo · OADuolingo interview questions
- Permutation Enumeration (Practice Reconstruction)Roblox · OARoblox interview questions
- Optimal Account BalancingVirtu Financial · OAVirtu Financial interview questions
- Enumerate Valid Clock TimesMicrosoft · OAMicrosoft interview questions
- SubsetsTemu · PHONE SCREENTemu interview questions
- Unique Single-Use Sum CombinationsLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Bounded Combination Sum with Signed CandidatesConfluent · ONSITE INTERVIEWConfluent interview questions