Hot100: N-Queens Incremental Build Tutorial

51. N-Queens is best learned by watching the code grow one small step at a time. This tutorial keeps only the teaching path: tiny example, first DFS skeleton, first correct version, column-only optimization, then full diagonal-state optimization. Problem The n-queens puzzle asks us to place n queens on an n x n chessboard so that no two queens attack each other. Given an integer n, return all distinct solutions. Each solution is represented as a list of strings where: ...

April 19, 2026 · 8 min · map[name:Jeanphilo]